-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for workers in svelte compilation
- Loading branch information
1 parent
bcb9c5b
commit e3876e6
Showing
111 changed files
with
978 additions
and
23 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
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,61 @@ | ||
const fs = require("fs"); | ||
const worker = require('@bazel/worker'); | ||
const svelte = require("svelte/compiler"); | ||
|
||
const outputJs = process.argv[3]; | ||
const input = process.argv[2]; | ||
async function compileSvelte(args) { | ||
const input = args[0] | ||
const outputJs = args[1] | ||
|
||
const svelte = require("svelte/compiler"); | ||
const source = await readFile(input); | ||
const result = svelte.compile(source, { | ||
format: "esm", | ||
generate: "dom", | ||
filename: outputJs | ||
}); | ||
|
||
await writeFile(outputJs, result.js.code); | ||
|
||
return true; | ||
} | ||
|
||
function writeFile(file, data) { | ||
return new Promise((resolve, reject) => { | ||
fs.writeFile(file, data, (err) => { | ||
if (err) { | ||
reject(err); | ||
return | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
function readFile(file) { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(file, 'utf8' , (err, data) => { | ||
if (err) { | ||
reject(err); | ||
return | ||
} | ||
resolve(data); | ||
}); | ||
}); | ||
} | ||
|
||
const source = fs.readFileSync(input, "utf8"); | ||
const result = svelte.compile(source, { | ||
format: "esm", | ||
generate: "dom", | ||
filename: outputJs | ||
}); | ||
function main(args) { | ||
if (worker.runAsWorker(process.argv)) { | ||
worker.log('Svelte running as a Bazel worker'); | ||
worker.runWorkerLoop(compileSvelte); | ||
} | ||
else { | ||
const paramFile = process.argv[2].replace(/^@/, ''); | ||
const commandLineArgs = require('fs').readFileSync(paramFile, 'utf-8').trim().split('\n'); | ||
console.log('Svelte running as a standalone process'); | ||
compileSvelte(commandLineArgs); | ||
} | ||
} | ||
|
||
fs.writeFileSync(outputJs, result.js.code); | ||
if (require.main === module) { | ||
main(process.argv.slice(2)); | ||
process.exitCode = 0; | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,66 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
"@bazel/[email protected]": | ||
version "2.3.0" | ||
resolved "https://registry.yarnpkg.com/@bazel/worker/-/worker-2.3.0.tgz#c2eca9505332377381c79715ec8d4fea70cad64f" | ||
integrity sha512-kz84SxTVokbkzB/WsLjH1qN6P045wG3oNbpRGFn4u1+rmAbklxVoQljxjmdh1o1KfBGYJaZx1SaxVLBPwVjMng== | ||
dependencies: | ||
protobufjs "6.8.8" | ||
|
||
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf" | ||
integrity sha1-m4sMxmPWaafY9vXQiToU00jzD78= | ||
|
||
"@protobufjs/base64@^1.1.2": | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/base64/-/base64-1.1.2.tgz#4c85730e59b9a1f1f349047dbf24296034bb2735" | ||
integrity sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg== | ||
|
||
"@protobufjs/codegen@^2.0.4": | ||
version "2.0.4" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/codegen/-/codegen-2.0.4.tgz#7ef37f0d010fb028ad1ad59722e506d9262815cb" | ||
integrity sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg== | ||
|
||
"@protobufjs/eventemitter@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz#355cbc98bafad5978f9ed095f397621f1d066b70" | ||
integrity sha1-NVy8mLr61ZePntCV85diHx0Ga3A= | ||
|
||
"@protobufjs/fetch@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/fetch/-/fetch-1.1.0.tgz#ba99fb598614af65700c1619ff06d454b0d84c45" | ||
integrity sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU= | ||
dependencies: | ||
"@protobufjs/aspromise" "^1.1.1" | ||
"@protobufjs/inquire" "^1.1.0" | ||
|
||
"@protobufjs/float@^1.0.2": | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/float/-/float-1.0.2.tgz#5e9e1abdcb73fc0a7cb8b291df78c8cbd97b87d1" | ||
integrity sha1-Xp4avctz/Ap8uLKR33jIy9l7h9E= | ||
|
||
"@protobufjs/inquire@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/inquire/-/inquire-1.1.0.tgz#ff200e3e7cf2429e2dcafc1140828e8cc638f089" | ||
integrity sha1-/yAOPnzyQp4tyvwRQIKOjMY48Ik= | ||
|
||
"@protobufjs/path@^1.1.2": | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/path/-/path-1.1.2.tgz#6cc2b20c5c9ad6ad0dccfd21ca7673d8d7fbf68d" | ||
integrity sha1-bMKyDFya1q0NzP0hynZz2Nf79o0= | ||
|
||
"@protobufjs/pool@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/pool/-/pool-1.1.0.tgz#09fd15f2d6d3abfa9b65bc366506d6ad7846ff54" | ||
integrity sha1-Cf0V8tbTq/qbZbw2ZQbWrXhG/1Q= | ||
|
||
"@protobufjs/utf8@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570" | ||
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA= | ||
|
||
"@rollup/[email protected]": | ||
version "15.0.0" | ||
resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-15.0.0.tgz#690d15a9d54ba829db93555bff9b98ff34e08574" | ||
|
@@ -46,11 +106,21 @@ | |
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" | ||
integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== | ||
|
||
"@types/long@^4.0.0": | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9" | ||
integrity sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w== | ||
|
||
"@types/node@*": | ||
version "14.6.0" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.6.0.tgz#7d4411bf5157339337d7cff864d9ff45f177b499" | ||
integrity sha512-mikldZQitV94akrc4sCcSjtJfsTKt4p+e/s0AGscVA6XArQ9kFclP+ZiYUMnq987rc6QlYxXv/EivqlfSLxpKA== | ||
|
||
"@types/node@^10.1.0": | ||
version "10.17.46" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.46.tgz#1cd867ebfe9957ab45951f2f715f8de5f3dab7a3" | ||
integrity sha512-Tice8a+sJtlP9C1EUo0DYyjq52T37b3LexVu3p871+kfIBIN+OQ7PKPei1oF3MgF39olEpUfxaLtD+QFc1k69Q== | ||
|
||
"@types/[email protected]": | ||
version "1.17.1" | ||
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" | ||
|
@@ -309,6 +379,11 @@ locate-path@^6.0.0: | |
dependencies: | ||
p-locate "^5.0.0" | ||
|
||
long@^4.0.0: | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" | ||
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== | ||
|
||
magic-string@^0.25.7: | ||
version "0.25.7" | ||
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051" | ||
|
@@ -379,6 +454,25 @@ process-nextick-args@^2.0.0, process-nextick-args@~2.0.0: | |
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" | ||
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== | ||
|
||
[email protected]: | ||
version "6.8.8" | ||
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.8.8.tgz#c8b4f1282fd7a90e6f5b109ed11c84af82908e7c" | ||
integrity sha512-AAmHtD5pXgZfi7GMpllpO3q1Xw1OYldr+dMUlAnffGTAhqkg72WdmSY71uKBF/JuyiKs8psYbtKrhi0ASCD8qw== | ||
dependencies: | ||
"@protobufjs/aspromise" "^1.1.2" | ||
"@protobufjs/base64" "^1.1.2" | ||
"@protobufjs/codegen" "^2.0.4" | ||
"@protobufjs/eventemitter" "^1.1.0" | ||
"@protobufjs/fetch" "^1.1.0" | ||
"@protobufjs/float" "^1.0.2" | ||
"@protobufjs/inquire" "^1.1.0" | ||
"@protobufjs/path" "^1.1.2" | ||
"@protobufjs/pool" "^1.1.0" | ||
"@protobufjs/utf8" "^1.1.0" | ||
"@types/long" "^4.0.0" | ||
"@types/node" "^10.1.0" | ||
long "^4.0.0" | ||
|
||
readable-stream@^2.3.5: | ||
version "2.3.7" | ||
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57" | ||
|
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,2 @@ | ||
build --symlink_prefix=dist/ | ||
build --strategy=SvelteCompile=worker | ||
build --symlink_prefix=dist/ |
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.