sliftutils 1.7.8 → 1.7.9
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/bundler/bundleEntry.ts +14 -10
- package/bundler/bundler.ts +6 -1
- package/package.json +1 -1
package/bundler/bundleEntry.ts
CHANGED
|
@@ -32,7 +32,6 @@ async function main() {
|
|
|
32
32
|
if (name.endsWith(".ts") || name.endsWith(".tsx")) {
|
|
33
33
|
name = name.split(".").slice(0, -1).join(".");
|
|
34
34
|
}
|
|
35
|
-
name += ".js";
|
|
36
35
|
|
|
37
36
|
let modules = Object.values(require.cache).filter(x => x?.id !== module.id);
|
|
38
37
|
|
|
@@ -42,16 +41,21 @@ async function main() {
|
|
|
42
41
|
entryPoints: [entryPoint],
|
|
43
42
|
});
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
await fs.promises.rename(tempPath, finalPath);
|
|
51
|
-
} finally {
|
|
44
|
+
// Two artifacts: `name.js` without the sourcemap (the sourcemap is usually bigger than the code
|
|
45
|
+
// itself, so this is what production serves) and `name.debug.js` with the inline sourcemap
|
|
46
|
+
// appended (serve it behind something like a ?debug query param).
|
|
47
|
+
async function write(finalPath: string, contents: string) {
|
|
48
|
+
let tempPath = `${finalPath}.tmp`;
|
|
52
49
|
try {
|
|
53
|
-
await fs.promises.
|
|
54
|
-
|
|
50
|
+
await fs.promises.writeFile(tempPath, contents);
|
|
51
|
+
await fs.promises.rename(tempPath, finalPath);
|
|
52
|
+
} finally {
|
|
53
|
+
try {
|
|
54
|
+
await fs.promises.unlink(tempPath);
|
|
55
|
+
} catch { }
|
|
56
|
+
}
|
|
55
57
|
}
|
|
58
|
+
await write(`${outputFolder}/${name}.js`, bundled.bundle);
|
|
59
|
+
await write(`${outputFolder}/${name}.debug.js`, bundled.bundle + "\n" + bundled.sourceMapComment);
|
|
56
60
|
}
|
|
57
61
|
main().catch(err => { console.error(err); process.exitCode = 1; }).finally(() => process.exit());
|
package/bundler/bundler.ts
CHANGED
|
@@ -9,7 +9,12 @@ export async function bundle(config: {
|
|
|
9
9
|
rootPath: string;
|
|
10
10
|
entryPoints: string[];
|
|
11
11
|
}): Promise<{
|
|
12
|
+
// The runnable bundle, WITHOUT the sourcemap comment (the sourcemap is usually bigger than the
|
|
13
|
+
// code itself, so the default artifact ships without it).
|
|
12
14
|
bundle: string;
|
|
15
|
+
// The trailing inline-sourcemap line comment. Append to `bundle` (with a newline) for the debug
|
|
16
|
+
// variant of the bundle.
|
|
17
|
+
sourceMapComment: string;
|
|
13
18
|
}> {
|
|
14
19
|
const { modules, rootPath, entryPoints } = config;
|
|
15
20
|
|
|
@@ -55,9 +60,9 @@ export async function bundle(config: {
|
|
|
55
60
|
code += `\n;globalThis.require(${JSON.stringify(entryPoint)});`;
|
|
56
61
|
}
|
|
57
62
|
code += "\n;});";
|
|
58
|
-
code += "\n" + encodeSourceMapLineComment(finalizeInProgressSourceMap(inProgressSourceMap));
|
|
59
63
|
return {
|
|
60
64
|
bundle: code,
|
|
65
|
+
sourceMapComment: encodeSourceMapLineComment(finalizeInProgressSourceMap(inProgressSourceMap)),
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
|