-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vendor workerbox to fix signals esm issue in some environments (#1155)
- Loading branch information
Showing
17 changed files
with
1,018 additions
and
25 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'@segment/analytics-signals': minor | ||
--- | ||
|
||
- Fix npm installation esm error by vendoring esm-only module workerbox |
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
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 +1,5 @@ | ||
module.exports = require("@internal/config").lintStagedConfig | ||
module.exports = { | ||
...require("@internal/config").lintStagedConfig, | ||
'src/lib/workerbox/*.{js,ts,html}': ['yarn workerbox'] | ||
} | ||
|
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
16 changes: 16 additions & 0 deletions
16
packages/signals/signals/scripts/assert-workerbox-built.sh
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,16 @@ | ||
#!/bin/sh | ||
# A CI script to ensure people remember to rebuild workerbox related files if workerbox changes | ||
|
||
node scripts/build-workerbox.js | ||
# Check for changes in the workerbox directory | ||
changed_files=$(git diff --name-only | grep 'lib/workerbox') | ||
|
||
# Check for changes in the workerbox directory | ||
if [ -n "$changed_files" ]; then | ||
echo "Error: Changes detected in the workerbox directory. Please commit the changed files:" | ||
echo "$changed_files" | ||
exit 1 | ||
else | ||
echo "Files have not changed" | ||
exit 0 | ||
fi |
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,64 @@ | ||
const fs = require('fs') | ||
const esbuild = require('esbuild') | ||
const path = require('path') | ||
|
||
// Note: This was adopted from the https://github.com/markwylde/workerbox/blob/master/build.js | ||
console.log('Building workerbox...') | ||
|
||
const DEBUG = process.env.DEBUG === 'true' | ||
if (DEBUG) console.log('Minification off.') | ||
|
||
async function writeFileWithDirs(filePath, data) { | ||
// Extract the directory path from the file path | ||
const dir = path.dirname(filePath) | ||
|
||
// Ensure the directory exists | ||
await fs.promises.mkdir(dir, { recursive: true }) | ||
|
||
// Write the file | ||
await fs.promises.writeFile(filePath, data, 'utf8') | ||
} | ||
|
||
async function build() { | ||
console.log(new Date(), 'rebuilding...') | ||
|
||
// clean up dist folder | ||
await fs.promises.rm('./src/lib/workerbox/dist', { | ||
recursive: true, | ||
force: true, | ||
}) | ||
|
||
await esbuild.build({ | ||
entryPoints: ['./src/lib/workerbox/worker.ts'], | ||
bundle: true, | ||
outfile: './src/lib/workerbox/dist/worker.js', | ||
minify: !DEBUG, | ||
}) | ||
|
||
const jsData = await fs.promises.readFile( | ||
'./src/lib/workerbox/dist/worker.js', | ||
'utf8' | ||
) | ||
|
||
const TEMPLATE_PLACEHOLDER = `{{WORKERSCRIPT}}` | ||
const htmlData = ( | ||
await fs.promises.readFile('./src/lib/workerbox/worker.html', 'utf8') | ||
).replace(TEMPLATE_PLACEHOLDER, jsData) | ||
|
||
await writeFileWithDirs('./src/lib/workerbox/dist/worker.html', htmlData) | ||
await writeFileWithDirs( | ||
'./src/lib/workerbox/worker.generated.ts', | ||
[ | ||
'/* eslint-disable */', | ||
`// built from /dist/worker.html`, | ||
`export default atob('${Buffer.from(htmlData).toString('base64')}');`, | ||
].join('\n') | ||
) | ||
} | ||
|
||
build() | ||
.then(() => console.log('Build successful')) | ||
.catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
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 |
---|---|---|
|
@@ -10,4 +10,4 @@ const createWorkerBox = jest.fn(() => { | |
}) | ||
}) | ||
|
||
export default createWorkerBox | ||
export { createWorkerBox } |
Oops, something went wrong.