Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dda110b
commit b10f6fc
Showing
10 changed files
with
269 additions
and
137 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const chalk = require('chalk') | ||
const replace = require('@rollup/plugin-replace') | ||
const getChecksum = require('./getChecksum') | ||
|
||
module.exports = function integrityCheck(options) { | ||
const { input, output, checksumPlaceholder } = options | ||
|
||
function injectChecksum(checksum) { | ||
return { | ||
SERVICE_WORKER_CHECKSUM: JSON.stringify(checksum), | ||
} | ||
} | ||
|
||
return { | ||
name: 'integrity-check', | ||
renderChunk(...args) { | ||
return replace(injectChecksum(this.checksum)).renderChunk(...args) | ||
}, | ||
transform(...args) { | ||
return replace(injectChecksum(this.checksum)).transform(...args) | ||
}, | ||
buildStart() { | ||
if (!fs.existsSync(input)) { | ||
this.error(`Failed to locate the Service Worker file at: ${input}`) | ||
} | ||
|
||
console.log('Signing the Service Worker at:\n%s', chalk.cyan(input)) | ||
|
||
this.checksum = getChecksum(input) | ||
const workerContent = fs.readFileSync(input, 'utf8') | ||
const publicWorkerContent = workerContent.replace( | ||
checksumPlaceholder, | ||
this.checksum, | ||
) | ||
|
||
this.emitFile({ | ||
type: 'asset', | ||
fileName: path.basename(output), | ||
source: publicWorkerContent, | ||
}) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const resolve = require('@rollup/plugin-node-resolve') | ||
const commonjs = require('@rollup/plugin-commonjs') | ||
const typescript = require('rollup-plugin-typescript2') | ||
const json = require('@rollup/plugin-json') | ||
const packageJson = require('./package.json') | ||
const integrityCheck = require('./config/plugins/rollup-integrity-check-plugin') | ||
const { | ||
SERVICE_WORKER_SOURCE_PATH, | ||
SERVICE_WORKER_BUILD_PATH, | ||
} = require('./config/constants') | ||
|
||
export default { | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: packageJson.main, | ||
name: 'MockServiceWorker', | ||
format: 'umd', | ||
}, | ||
{ | ||
file: packageJson.module, | ||
format: 'es', | ||
}, | ||
], | ||
plugins: [ | ||
resolve({ | ||
preferBuiltins: false, | ||
mainFields: ['module', 'main', 'jsnext:main', 'browser'], | ||
extensions: ['.js', '.jsx', '.ts', '.tsx'], | ||
}), | ||
json(), | ||
integrityCheck({ | ||
checksumPlaceholder: '<INTEGRITY_CHECKSUM>', | ||
input: SERVICE_WORKER_SOURCE_PATH, | ||
output: SERVICE_WORKER_BUILD_PATH, | ||
}), | ||
commonjs(), | ||
typescript({ | ||
useTsconfigDeclarationDir: true, | ||
}), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
{ | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"module": "es2015", | ||
"strict": true, | ||
"target": "es6", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true, | ||
"declaration": true, | ||
"declarationDir": "./lib", | ||
"declarationDir": "lib/types", | ||
"lib": ["es2017", "ESNext.AsyncIterable", "dom", "webworker"] | ||
}, | ||
"include": ["global.d.ts", "src/**/*.ts"], | ||
"exclude": ["node_modules", "**/*.spec.ts"] | ||
"exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"] | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.