Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TINY-11415: added static service worker #147

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 14.1.5 - 2024-10-18

### Added

- Added static mock service worker js file mapping. #TINY-11415

## 14.1.4 - 2024-03-27

### Fixed
Expand Down
38 changes: 27 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,35 @@ timestamps {

stage("test") {
exec('yarn test')

bedrockBrowsers(
prepareTests: {
yarnInstall()
exec('yarn build')
},
testDirs: [ 'modules/sample/src/test/ts/**/pass' ],
custom: '--config modules/sample/tsconfig.json --customRoutes modules/sample/routes.json --polyfills Promise Symbol'
)
}
}

// Testing
stage("bedrock testing") {
bedrockRemoteBrowsers(
platforms: [
[ browser: 'chrome', provider: 'aws', buckets: 2 ],
[ browser: 'firefox', provider: 'aws', buckets: 2 ],
[ browser: 'edge', provider: 'lambdatest', buckets: 1 ],
[ browser: 'chrome', provider: 'lambdatest', os: 'macOS Sonoma', buckets: 1 ],
[ browser: 'firefox', provider: 'lambdatest', os: 'macOS Sonoma', buckets: 1 ],
[ browser: 'safari', provider: 'lambdatest', os: 'macOS Sonoma', buckets: 1 ],
],
prepareTests: {
yarnInstall()
sh 'yarn build'
},
testDirs: [ 'modules/sample/src/test/ts/**/pass' ],
custom: '--config modules/sample/tsconfig.json --customRoutes modules/sample/routes.json --polyfills Promise Symbol'
)
}

if (isReleaseBranch()) {
stage("publish") {
// Publish
if (isReleaseBranch()) {
stage("publish") {
tinyPods.node() {
yarnInstall()
sh 'yarn build'
tinyNpm.withNpmPublishCredentials {
// We need to tell git to ignore the changes to .npmrc when publishing
exec('git update-index --assume-unchanged .npmrc')
Expand Down
23 changes: 23 additions & 0 deletions modules/server/src/main/ts/bedrock/server/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,26 @@ export const nodeResolve = (method: HTTPMethod, prefix: string, source: string):
};
};

export const nodeResolveFile = (method: HTTPMethod, url: string, projectDir: string, moduleName: string, subPath: string): Route => {
const go: RouteGoFunc = (request, response, done) => {
const failure = (status: number, data: string) => {
doResponse(request, response, status, 'text/plain', data);
done();
};

try {
const moduleResolvedPath = require.resolve(path.join(moduleName, 'package.json'), { paths: [ projectDir ] });
const router = createServer(path.dirname(moduleResolvedPath));
request.url = '/' + subPath;
router(request, response, done);
} catch (e) {
failure(404, `Failed to resolve static node file for module path: ${moduleName}/${subPath}`);
}
};

return {
matches: [Matchers.methodMatch(method), Matchers.urlMatch(url)],
go
};
};

Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const generate = async (mode: string, projectdir: string, basedir: string
Routes.routing('GET', '/lib/jquery', path.dirname(require.resolve('jquery'))),
Routes.routing('GET', '/lib/core-js-bundle', path.dirname(require.resolve('core-js-bundle'))),
Routes.routing('GET', '/css', path.join(basedir, 'src/resources/css')),
Routes.nodeResolveFile('GET', '/mockServiceWorker.js', projectdir, 'msw', 'lib/mockServiceWorker.js'),

// test code
Routes.asyncJs('GET', '/compiled/tests.js', (done) => {
Expand Down
Loading