-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #433 from jsenv/migrate_workflow_packages
Migrate workflow packages
- Loading branch information
Showing
203 changed files
with
21,258 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 jsenv | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,36 @@ | ||
# Dynamic import worker | ||
|
||
[![npm package](https://img.shields.io/npm/v/@jsenv/dynamic-import-worker.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/dynamic-import-worker) | ||
|
||
Bypass node cache on dynamic import thanks to worker | ||
|
||
# Example | ||
|
||
_docs/demo/random_number.mjs_ | ||
|
||
```js | ||
export const randomNumber = Math.random(); | ||
``` | ||
|
||
_docs/demo/demo.mjs_ | ||
|
||
```js | ||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
const randomNumberFileUrl = new URL( | ||
"./random_number.mjs#randomNumber", | ||
import.meta.url, | ||
); | ||
|
||
const randomNumberA = await importOneExportFromFile(randomNumberExportUrl); | ||
const randomNumberB = await importOneExportFromFile(randomNumberExportUrl); | ||
|
||
console.log(randomNumberA); | ||
console.log(randomNumberB); | ||
``` | ||
|
||
```console | ||
> node ./docs/demo/demo.mjs | ||
0.5362418125287491 | ||
0.35129949391010595 | ||
``` |
10 changes: 10 additions & 0 deletions
10
packages/independent/dynamic-import-worker/docs/demo/demo.mjs
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 @@ | ||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
const randomNumberFileUrl = new URL("./random_number.mjs", import.meta.url); | ||
const randomNumberExportUrl = `${randomNumberFileUrl}#randomNumber`; | ||
|
||
const randomNumberA = await importOneExportFromFile(randomNumberExportUrl); | ||
const randomNumberB = await importOneExportFromFile(randomNumberExportUrl); | ||
|
||
console.log(randomNumberA); | ||
console.log(randomNumberB); |
1 change: 1 addition & 0 deletions
1
packages/independent/dynamic-import-worker/docs/demo/random_number.mjs
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 @@ | ||
export const randomNumber = Math.random(); |
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,31 @@ | ||
{ | ||
"name": "@jsenv/dynamic-import-worker", | ||
"version": "1.2.1", | ||
"description": "Bypass node cache on dynamic import thanks to worker", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jsenv/core", | ||
"directory": "packages/independent/dynamic-import-worker" | ||
}, | ||
"engines": { | ||
"node": ">=20.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./src/main.js" | ||
}, | ||
"./*": "./*" | ||
}, | ||
"files": [ | ||
"/src/" | ||
], | ||
"scripts": { | ||
"test": "node ./scripts/test.mjs" | ||
}, | ||
"dependencies": {} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/independent/dynamic-import-worker/scripts/test.mjs
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,12 @@ | ||
import { executeTestPlan, nodeWorkerThread } from "@jsenv/test"; | ||
|
||
await executeTestPlan({ | ||
rootDirectoryUrl: new URL("../", import.meta.url), | ||
testPlan: { | ||
"./tests/**/*.test.mjs": { | ||
node: { | ||
runtime: nodeWorkerThread(), | ||
}, | ||
}, | ||
}, | ||
}); |
67 changes: 67 additions & 0 deletions
67
packages/independent/dynamic-import-worker/src/import_one_export_from_file.js
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,67 @@ | ||
import { Worker } from "node:worker_threads"; | ||
import { existsSync } from "node:fs"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
// we use a worker to bypass node cache on dynamic import | ||
const WORKER_COLLECTING_ONE_EXPORT_FILE_URL = new URL( | ||
"./worker_collecting_one_export.js", | ||
import.meta.url, | ||
); | ||
|
||
export const importOneExportFromFile = async ( | ||
fileUrl, | ||
{ env = process.env, params } = {}, | ||
) => { | ||
const { hash, urlWithoutHash } = extractHashFromUrl(fileUrl); | ||
if (!hash) { | ||
throw new Error(`no hash found in fileUrl ${fileUrl}`); | ||
} | ||
|
||
const url = urlWithoutHash; | ||
const exportName = hash.slice(1); | ||
|
||
const exists = existsSync(fileURLToPath(new URL(url))); | ||
if (!exists) { | ||
throw new Error(`File not found at ${url}`); | ||
} | ||
|
||
const worker = new Worker(WORKER_COLLECTING_ONE_EXPORT_FILE_URL, { | ||
env, | ||
workerData: { | ||
url, | ||
exportName, | ||
params, | ||
}, | ||
}); | ||
|
||
let errorData; | ||
let messageData; | ||
await new Promise((resolve) => { | ||
worker.once("message", (message) => { | ||
messageData = message; | ||
}); | ||
worker.once("error", (error) => { | ||
errorData = error; | ||
}); | ||
worker.once("exit", () => { | ||
resolve(); | ||
}); | ||
}); | ||
|
||
if (errorData) { | ||
const error = new Error(errorData.message); | ||
error.name = errorData.name; | ||
error.stack = errorData.stack; | ||
throw error; | ||
} | ||
|
||
return messageData; | ||
}; | ||
|
||
const extractHashFromUrl = (url) => { | ||
const urlObject = new URL(url); | ||
const { hash } = urlObject; | ||
urlObject.hash = ""; | ||
const urlWithoutHash = String(urlObject); | ||
return { hash, urlWithoutHash }; | ||
}; |
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,7 @@ | ||
/* | ||
* This file is the first file executed by code using the package | ||
* Its responsability is to export what is documented | ||
* Ideally this file should be kept simple to help discovering codebase progressively. | ||
*/ | ||
|
||
export { importOneExportFromFile } from "./import_one_export_from_file.js"; |
17 changes: 17 additions & 0 deletions
17
packages/independent/dynamic-import-worker/src/worker_collecting_one_export.js
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,17 @@ | ||
import { parentPort, workerData } from "node:worker_threads"; | ||
|
||
const { url, exportName, params } = workerData; | ||
const namespace = await import(url); | ||
|
||
if (!Object.prototype.hasOwnProperty.call(namespace, exportName)) { | ||
throw new Error(`No export named "${exportName}" in ${url}`); | ||
} | ||
|
||
const exportValue = namespace[exportName]; | ||
if (typeof exportValue === "function") { | ||
const metrics = await exportValue(params); | ||
parentPort.postMessage(metrics); | ||
} else { | ||
const metrics = exportValue; | ||
parentPort.postMessage(metrics); | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/independent/dynamic-import-worker/tests/basic/basic.test.mjs
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 @@ | ||
import { assert } from "@jsenv/assert"; | ||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
{ | ||
const actual = await importOneExportFromFile( | ||
`${new URL("./exporting_answer.mjs", import.meta.url)}#answer`, | ||
); | ||
const expect = 42; | ||
assert({ actual, expect }); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/independent/dynamic-import-worker/tests/basic/exporting_answer.mjs
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 @@ | ||
export const answer = 42; |
17 changes: 17 additions & 0 deletions
17
packages/independent/dynamic-import-worker/tests/export_missing/export_missing.test.mjs
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,17 @@ | ||
import { assert } from "@jsenv/assert"; | ||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
// export missing | ||
try { | ||
await importOneExportFromFile( | ||
`${new URL("./exporting_toto.mjs", import.meta.url)}#answer`, | ||
); | ||
throw new Error("should throw"); | ||
} catch (e) { | ||
const actual = e.message; | ||
const expect = `No export named "answer" in ${new URL( | ||
"./exporting_toto.mjs", | ||
import.meta.url, | ||
)}`; | ||
assert({ actual, expect }); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/independent/dynamic-import-worker/tests/export_missing/exporting_toto.mjs
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 @@ | ||
export const toto = 42; |
16 changes: 16 additions & 0 deletions
16
packages/independent/dynamic-import-worker/tests/file_missing/file_missing.test.mjs
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 @@ | ||
import { assert } from "@jsenv/assert"; | ||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
// file missing | ||
try { | ||
await importOneExportFromFile( | ||
`${new URL("./toto.mjs", import.meta.url)}#answer`, | ||
); | ||
throw new Error("should throw"); | ||
} catch (e) { | ||
const actual = e; | ||
const expect = new Error( | ||
`File not found at ${new URL("./toto.mjs", import.meta.url)}`, | ||
); | ||
assert({ actual, expect }); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/independent/dynamic-import-worker/tests/importing_function/exporting_getter.mjs
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,3 @@ | ||
export const get = (value) => { | ||
return value; | ||
}; |
23 changes: 23 additions & 0 deletions
23
...es/independent/dynamic-import-worker/tests/importing_function/importing_function.test.mjs
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,23 @@ | ||
import { assert } from "@jsenv/assert"; | ||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
{ | ||
const withoutParams = await importOneExportFromFile( | ||
`${new URL("./exporting_getter.mjs", import.meta.url)}#get`, | ||
); | ||
const withParam42 = await importOneExportFromFile( | ||
`${new URL("./exporting_getter.mjs", import.meta.url)}#get`, | ||
{ | ||
params: 42, | ||
}, | ||
); | ||
const actual = { | ||
withoutParams, | ||
withParam42, | ||
}; | ||
const expect = { | ||
withoutParams: undefined, | ||
withParam42: 42, | ||
}; | ||
assert({ actual, expect }); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/independent/dynamic-import-worker/tests/importing_with_env/exporting_answer.mjs
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 @@ | ||
export const answer = process.env.TOTO ? 42 : 43; |
25 changes: 25 additions & 0 deletions
25
...es/independent/dynamic-import-worker/tests/importing_with_env/importing_with_env.test.mjs
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,25 @@ | ||
import { assert } from "@jsenv/assert"; | ||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
{ | ||
const withoutEnv = await importOneExportFromFile( | ||
`${new URL("./exporting_answer.mjs", import.meta.url)}#answer`, | ||
); | ||
const withTotoEnv = await importOneExportFromFile( | ||
`${new URL("./exporting_answer.mjs", import.meta.url)}#answer`, | ||
{ | ||
env: { | ||
TOTO: "true", | ||
}, | ||
}, | ||
); | ||
const actual = { | ||
withoutEnv, | ||
withTotoEnv, | ||
}; | ||
const expect = { | ||
withoutEnv: 43, | ||
withTotoEnv: 42, | ||
}; | ||
assert({ actual, expect }); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/independent/dynamic-import-worker/tests/runtime_error/runtime_error.mjs
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 @@ | ||
throw new Error("here"); |
14 changes: 14 additions & 0 deletions
14
packages/independent/dynamic-import-worker/tests/runtime_error/runtime_error.test.mjs
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,14 @@ | ||
import { assert } from "@jsenv/assert"; | ||
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"; | ||
|
||
// runtime error | ||
try { | ||
await importOneExportFromFile( | ||
`${new URL("./runtime_error.mjs", import.meta.url)}#answer`, | ||
); | ||
throw new Error("should throw"); | ||
} catch (e) { | ||
const actual = e.message; | ||
const expect = "here"; | ||
assert({ actual, expect }); | ||
} |
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,8 @@ | ||
# 14.0.0 | ||
|
||
- Rename reportFileSizeImpact into reportFileSizeImpactInGitHubPullRequest | ||
|
||
# 13.0.0 | ||
|
||
- Rename fileSizeReportModulePath into fileSizeReportUrl | ||
- Reduce number of decimals when file size is big |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 jsenv | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.