-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Support building for externally shared js builtins (#91)"
This reverts commit 1c5072c.
- Loading branch information
1 parent
1de1228
commit fa6a86c
Showing
8 changed files
with
865 additions
and
460 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"@babel/plugin-transform-modules-commonjs", | ||
{ | ||
"strict": 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
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,30 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [14.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm test |
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,72 +1,25 @@ | ||
const fs = require('fs'); | ||
const { buildSync } = require('esbuild'); | ||
const terser = require('terser'); | ||
|
||
const { EXTERNAL_PATH } = process.env; | ||
const MINIFY = !EXTERNAL_PATH; | ||
const MINIFY = true; | ||
|
||
try { fs.mkdirSync('./dist'); } | ||
catch (e) {} | ||
|
||
const wasmBuffer = fs.readFileSync('./lib/lexer.wasm'); | ||
const jsSource = fs.readFileSync('./src/lexer.js').toString(); | ||
const pjson = JSON.parse(fs.readFileSync('./package.json').toString()); | ||
|
||
buildSync({ | ||
entryPoints: ['./src/lexer.js'], | ||
outfile: './dist/lexer.mjs', | ||
bundle: true, | ||
minify: MINIFY, | ||
platform: 'node', | ||
format: 'esm', | ||
banner: { | ||
js: `/* cjs-module-lexer ${pjson.version} */` | ||
}, | ||
define: EXTERNAL_PATH ? { | ||
WASM_BINARY: 'undefined', | ||
EXTERNAL_PATH: `'${EXTERNAL_PATH}'`, | ||
} : { | ||
WASM_BINARY: `'${wasmBuffer.toString('base64')}'`, | ||
EXTERNAL_PATH: 'undefined' | ||
} | ||
}) | ||
const jsSourceProcessed = jsSource.replace('WASM_BINARY', wasmBuffer.toString('base64')); | ||
|
||
if (EXTERNAL_PATH) { | ||
buildSync({ | ||
stdin: { | ||
contents: `'use strict'; | ||
let lazy; | ||
async function init () { | ||
if (!lazy) { | ||
lazy = await import(require('node:url').pathToFileURL(require('node:module').createRequire('${EXTERNAL_PATH}/dist/lexer.js').resolve('./lexer.mjs'))); | ||
const minified = MINIFY && terser.minify(jsSourceProcessed, { | ||
module: true, | ||
output: { | ||
preamble: `/* cjs-module-lexer ${pjson.version} */` | ||
} | ||
module.exports = lazy; | ||
return lazy.init(); | ||
} | ||
function parse (source, name = '@') { | ||
if (!lazy) | ||
throw new Error('Not initialized'); | ||
return lazy.parse(source, name); | ||
} | ||
}); | ||
|
||
module.exports = { init, parse };`, | ||
loader: 'js', | ||
}, | ||
outfile: './dist/lexer.js', | ||
minify: MINIFY, | ||
platform: 'node', | ||
format: 'cjs', | ||
}); | ||
} else { | ||
buildSync({ | ||
entryPoints: ['./dist/lexer.mjs'], | ||
outfile: './dist/lexer.js', | ||
minify: MINIFY, | ||
platform: 'node', | ||
format: 'cjs', | ||
banner: { | ||
js: `/* cjs-module-lexer ${pjson.version} */` | ||
} | ||
}) | ||
} | ||
if (minified.error) | ||
throw minified.error; | ||
|
||
fs.writeFileSync('./dist/lexer.mjs', minified ? minified.code : jsSourceProcessed); |
Oops, something went wrong.