-
Notifications
You must be signed in to change notification settings - Fork 44
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
9b7c657
commit fcd2541
Showing
27 changed files
with
1,137 additions
and
208 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
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,37 @@ | ||
NODE_PATH := $(dir $(shell which node)) | ||
HEADERS_URL := $(shell node -p "process.release.headersUrl") | ||
NODE_VERSION := $(shell node -p "process.version") | ||
|
||
INCS_Debug := \ | ||
-Ibuild/node-$(NODE_VERSION)/include/node \ | ||
-I$(shell node -p "require('node-addon-api').include_dir") | ||
|
||
SRC := src/binding.cc src/Watcher.cc src/Backend.cc src/DirTree.cc src/Glob.cc src/Debounce.cc src/shared/BruteForceBackend.cc src/unix/legacy.cc src/wasm/WasmBackend.cc | ||
FLAGS := $(INCS_Debug) \ | ||
-Oz \ | ||
-flto \ | ||
-fwasm-exceptions \ | ||
-DNAPI_HAS_THREADS=1 \ | ||
-sEXPORTED_FUNCTIONS="['_napi_register_wasm_v1', '_wasm_backend_event_handler', '_malloc', '_free', '_on_timeout']" \ | ||
-sERROR_ON_UNDEFINED_SYMBOLS=0 \ | ||
-s INITIAL_MEMORY=524288000 | ||
|
||
build/node-headers.tar.gz: | ||
curl $(HEADERS_URL) -o build/node-headers.tar.gz | ||
|
||
build/node-$(NODE_VERSION): build/node-headers.tar.gz | ||
tar -xvf build/node-headers.tar.gz -C build | ||
touch build/node-$(NODE_VERSION) | ||
|
||
build/Release/watcher.wasm: build/node-$(NODE_VERSION) $(SRC) | ||
mkdir -p build/Release | ||
em++ $(FLAGS) -sDECLARE_ASM_MODULE_EXPORTS=0 -o build/Release/watcher.js $(SRC) | ||
|
||
build/Debug/watcher.wasm: build/node-$(NODE_VERSION) $(SRC) | ||
mkdir -p build/Debug | ||
em++ -g $(FLAGS) -o build/Debug/watcher.js $(SRC) | ||
|
||
wasm: build/Release/watcher.wasm | ||
wasm-debug: build/Debug/watcher.wasm | ||
|
||
.PHONY: wasm wasm-debug |
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,49 @@ | ||
const exec = require('child_process').execSync; | ||
const fs = require('fs'); | ||
const pkg = require('../package.json'); | ||
|
||
const dir = `${__dirname}/..`; | ||
try { | ||
fs.mkdirSync(dir + '/npm/wasm'); | ||
} catch (err) { } | ||
|
||
let dts = fs.readFileSync(`${dir}/index.d.ts`, 'utf8'); | ||
dts += ` | ||
/** Initializes the web assembly module. */ | ||
export default function init(input?: string | URL | Request): Promise<void>; | ||
`; | ||
fs.writeFileSync(`${dir}/npm/wasm/index.d.ts`, dts); | ||
|
||
let readme = fs.readFileSync(`${dir}/README.md`, 'utf8'); | ||
readme = readme.replace('# ⚡️ Lightning CSS', '# ⚡️ lightningcss-wasm'); | ||
fs.writeFileSync(`${dir}/npm/wasm/README.md`, readme); | ||
|
||
let js = fs.readFileSync(`${dir}/wasm/index.mjs`, 'utf8'); | ||
js = js.replace('../build/Debug/watcher.wasm', 'watcher.wasm'); | ||
js = js.replace('../wrapper.js', './wrapper.js'); | ||
fs.writeFileSync(`${dir}/npm/wasm/index.mjs`, js); | ||
|
||
fs.copyFileSync(`${dir}/wrapper.js`, `${dir}/npm/wasm/wrapper.js`); | ||
fs.copyFileSync(`${dir}/wasm/watcher.wasm`, `${dir}/npm/wasm/watcher.wasm`); | ||
|
||
let wasmPkg = { ...pkg }; | ||
wasmPkg.name = '@parcel/watcher-wasm'; | ||
wasmPkg.main = 'index.mjs'; | ||
wasmPkg.module = 'index.mjs'; | ||
wasmPkg.types = 'index.d.ts'; | ||
wasmPkg.sideEffects = false; | ||
wasmPkg.files = ['*.js', '*.mjs', '*.d.ts', '*.wasm']; | ||
wasmPkg.dependencies = { | ||
'napi-wasm': pkg.devDependencies['napi-wasm'], | ||
'is-glob': pkg.dependencies['is-glob'], | ||
'micromatch': pkg.dependencies['micromatch'] | ||
}; | ||
delete wasmPkg.exports; | ||
delete wasmPkg.binary; | ||
delete wasmPkg['lint-staged']; | ||
delete wasmPkg.husky; | ||
delete wasmPkg.devDependencies; | ||
delete wasmPkg.optionalDependencies; | ||
delete wasmPkg.targets; | ||
delete wasmPkg.scripts; | ||
fs.writeFileSync(`${dir}/npm/wasm/package.json`, JSON.stringify(wasmPkg, false, 2) + '\n'); |
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
Oops, something went wrong.