@upleveled/preflight 9.0.1 → 9.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/preflight.js +33 -0
- package/package.json +2 -3
- package/bin/preflight.sh +0 -43
package/bin/preflight.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --disable-warning=ExperimentalWarning
|
|
2
|
+
|
|
3
|
+
import { registerHooks, stripTypeScriptTypes } from 'node:module';
|
|
4
|
+
|
|
5
|
+
const tsRegex = /^file:.*(?<!\.d)\.m?ts$/;
|
|
6
|
+
|
|
7
|
+
// Intercept .ts / .mts files (skipping .d.ts files) and
|
|
8
|
+
// transpile to JS, returning ES module
|
|
9
|
+
registerHooks({
|
|
10
|
+
load(url, context, nextLoad) {
|
|
11
|
+
if (tsRegex.test(url)) {
|
|
12
|
+
return {
|
|
13
|
+
format: 'module',
|
|
14
|
+
source: stripTypeScriptTypes(
|
|
15
|
+
/** @type {import('node:module').ModuleSource} */ (
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- ModuleSource returns useful information from .toString()
|
|
17
|
+
nextLoad(url).source
|
|
18
|
+
).toString(),
|
|
19
|
+
{
|
|
20
|
+
mode: 'transform',
|
|
21
|
+
sourceUrl: url,
|
|
22
|
+
},
|
|
23
|
+
),
|
|
24
|
+
shortCircuit: true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return nextLoad(url, context);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Path to entry point
|
|
33
|
+
await import('../src/index.ts');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upleveled/preflight",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.3",
|
|
4
4
|
"repository": "upleveled/preflight",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "UpLeveled (https://github.com/upleveled)",
|
|
@@ -12,10 +12,9 @@
|
|
|
12
12
|
"module": "./src/index.ts",
|
|
13
13
|
"types": "./src/index.ts",
|
|
14
14
|
"bin": {
|
|
15
|
-
"preflight": "./bin/preflight.
|
|
15
|
+
"preflight": "./bin/preflight.js"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"./bin/preflight.js",
|
|
19
18
|
"src"
|
|
20
19
|
],
|
|
21
20
|
"dependencies": {
|
package/bin/preflight.sh
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
|
|
3
|
-
set -o errexit
|
|
4
|
-
set -o nounset
|
|
5
|
-
set -o pipefail
|
|
6
|
-
|
|
7
|
-
exec node --disable-warning=ExperimentalWarning --input-type=module --eval '
|
|
8
|
-
import { registerHooks, stripTypeScriptTypes } from "node:module";
|
|
9
|
-
import { dirname, resolve } from "node:path";
|
|
10
|
-
import { argv } from "node:process";
|
|
11
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
12
|
-
|
|
13
|
-
const tsRegex = /^file:.*(?<!\.d)\.m?ts$/;
|
|
14
|
-
|
|
15
|
-
// Intercept .ts / .mts files (skipping .d.ts files) and
|
|
16
|
-
// transpile to JS, returning ES module
|
|
17
|
-
registerHooks({
|
|
18
|
-
load(url, context, nextLoad) {
|
|
19
|
-
if (tsRegex.test(url)) {
|
|
20
|
-
return {
|
|
21
|
-
format: "module",
|
|
22
|
-
source: stripTypeScriptTypes(nextLoad(url).source.toString(), {
|
|
23
|
-
mode: "transform",
|
|
24
|
-
sourceUrl: url,
|
|
25
|
-
}),
|
|
26
|
-
shortCircuit: true,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return nextLoad(url, context);
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
await import(
|
|
35
|
-
pathToFileURL(
|
|
36
|
-
resolve(
|
|
37
|
-
dirname(argv[1]),
|
|
38
|
-
// Path to entry point
|
|
39
|
-
"../src/index.ts",
|
|
40
|
-
),
|
|
41
|
-
).href
|
|
42
|
-
);
|
|
43
|
-
' "$0" "$@"
|