@speedkit/cli 4.22.0 → 4.22.1
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/CHANGELOG.md +7 -0
- package/README.md +1 -1
- package/dist/services/bundler/bundle-service.d.ts +12 -0
- package/dist/services/bundler/bundle-service.js +28 -1
- package/dist/services/bundler/bundle-service.spec.d.ts +1 -0
- package/dist/services/bundler/bundle-service.spec.js +54 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [4.22.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.22.0...v4.22.1) (2026-08-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **bundler:** resolve alias targets from the customer directory ([ad30e2a](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/ad30e2ac48a84c7592dd59d41004c301df212205))
|
|
7
|
+
|
|
1
8
|
# [4.22.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v4.21.0...v4.22.0) (2026-08-20)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -14,6 +14,18 @@ export declare class BundleService {
|
|
|
14
14
|
logLevel?: LogLevel;
|
|
15
15
|
platform?: "browser" | "node" | "neutral";
|
|
16
16
|
}): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Turns each alias target into an absolute path, resolved from the same directory the bundled
|
|
19
|
+
* code resolves its own imports from.
|
|
20
|
+
*
|
|
21
|
+
* esbuild resolves an alias target from its working directory, not from the entry point's
|
|
22
|
+
* resolveDir. `{ "node-fetch": "node-fetch-native" }` therefore only resolved while `sk` ran
|
|
23
|
+
* inside the customer checkout, and failed from anywhere else — even though the bundled code
|
|
24
|
+
* could import the very same module by name.
|
|
25
|
+
*
|
|
26
|
+
* A target that is not installed stays a bare name, so esbuild reports it as before.
|
|
27
|
+
*/
|
|
28
|
+
private resolveAliases;
|
|
17
29
|
private entryPointsPlugin;
|
|
18
30
|
baqendPlugin(basePaths: BundleBasePaths): {
|
|
19
31
|
name: string;
|
|
@@ -4,6 +4,7 @@ import { URL } from "node:url";
|
|
|
4
4
|
import { BundleResolveError } from "./error/bundle-resolve-error.js";
|
|
5
5
|
import { BundleFetchError } from "./error/bundle-fetch-error.js";
|
|
6
6
|
import { resolve } from "node:path";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
7
8
|
const importCache = {};
|
|
8
9
|
export class BundleService {
|
|
9
10
|
moduleDiscoveryDir;
|
|
@@ -29,13 +30,39 @@ export class BundleService {
|
|
|
29
30
|
entryPoints: Object.keys(entryPoints),
|
|
30
31
|
platform: platform || "neutral",
|
|
31
32
|
logLevel,
|
|
32
|
-
alias,
|
|
33
|
+
alias: this.resolveAliases(alias),
|
|
33
34
|
});
|
|
34
35
|
return result.outputFiles
|
|
35
36
|
.map((outputFile) => outputFile.text)
|
|
36
37
|
.join("")
|
|
37
38
|
.trim();
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Turns each alias target into an absolute path, resolved from the same directory the bundled
|
|
42
|
+
* code resolves its own imports from.
|
|
43
|
+
*
|
|
44
|
+
* esbuild resolves an alias target from its working directory, not from the entry point's
|
|
45
|
+
* resolveDir. `{ "node-fetch": "node-fetch-native" }` therefore only resolved while `sk` ran
|
|
46
|
+
* inside the customer checkout, and failed from anywhere else — even though the bundled code
|
|
47
|
+
* could import the very same module by name.
|
|
48
|
+
*
|
|
49
|
+
* A target that is not installed stays a bare name, so esbuild reports it as before.
|
|
50
|
+
*/
|
|
51
|
+
resolveAliases(alias) {
|
|
52
|
+
if (Object.keys(alias).length === 0) {
|
|
53
|
+
return alias;
|
|
54
|
+
}
|
|
55
|
+
// The filename never has to exist; only its directory decides where the lookup starts.
|
|
56
|
+
const requireFrom = createRequire(resolve(this.moduleDiscoveryDir, "noop.js"));
|
|
57
|
+
return Object.fromEntries(Object.entries(alias).map(([from, to]) => {
|
|
58
|
+
try {
|
|
59
|
+
return [from, requireFrom.resolve(to)];
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return [from, to];
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
39
66
|
entryPointsPlugin(entryPoints) {
|
|
40
67
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
41
68
|
const me = this;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { after, before, describe, it } from "mocha";
|
|
3
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { BundleService } from "./bundle-service.js";
|
|
7
|
+
/**
|
|
8
|
+
* The customer checkout installs the modules a document handler imports, so resolution must follow
|
|
9
|
+
* the customer directory rather than the directory `sk` happens to run in. The fixture below is
|
|
10
|
+
* only reachable from the customer directory, which is what makes the assertion meaningful.
|
|
11
|
+
*/
|
|
12
|
+
describe("BundleService alias resolution", () => {
|
|
13
|
+
const MARKER = "fixture-fetch-implementation";
|
|
14
|
+
let customerDirectory;
|
|
15
|
+
before(() => {
|
|
16
|
+
customerDirectory = mkdtempSync(join(tmpdir(), "sk-bundle-"));
|
|
17
|
+
const packageDirectory = join(customerDirectory, "node_modules", "fetch-native-fixture");
|
|
18
|
+
mkdirSync(packageDirectory, { recursive: true });
|
|
19
|
+
writeFileSync(join(packageDirectory, "package.json"), JSON.stringify({
|
|
20
|
+
name: "fetch-native-fixture",
|
|
21
|
+
version: "1.0.0",
|
|
22
|
+
main: "index.js",
|
|
23
|
+
}));
|
|
24
|
+
writeFileSync(join(packageDirectory, "index.js"), `module.exports = "${MARKER}";`);
|
|
25
|
+
});
|
|
26
|
+
after(() => {
|
|
27
|
+
rmSync(customerDirectory, { recursive: true, force: true });
|
|
28
|
+
});
|
|
29
|
+
it("resolves an alias target from the customer directory, not from the working directory", async () => {
|
|
30
|
+
const bundle = await new BundleService(customerDirectory).bundle({
|
|
31
|
+
entryPoints: {
|
|
32
|
+
"handler.js": "module.exports = require('node-fetch');",
|
|
33
|
+
},
|
|
34
|
+
minify: false,
|
|
35
|
+
platform: "node",
|
|
36
|
+
logLevel: "silent",
|
|
37
|
+
alias: { "node-fetch": "fetch-native-fixture" },
|
|
38
|
+
});
|
|
39
|
+
expect(bundle).to.contain(MARKER);
|
|
40
|
+
});
|
|
41
|
+
it("leaves an uninstalled alias target to esbuild", async () => {
|
|
42
|
+
const bundling = new BundleService(customerDirectory).bundle({
|
|
43
|
+
entryPoints: {
|
|
44
|
+
"handler.js": "module.exports = require('node-fetch');",
|
|
45
|
+
},
|
|
46
|
+
minify: false,
|
|
47
|
+
platform: "node",
|
|
48
|
+
logLevel: "silent",
|
|
49
|
+
alias: { "node-fetch": "not-installed-anywhere" },
|
|
50
|
+
});
|
|
51
|
+
const error = await bundling.then(() => undefined, (reason) => reason);
|
|
52
|
+
expect(String(error)).to.contain("not-installed-anywhere");
|
|
53
|
+
});
|
|
54
|
+
});
|
package/oclif.manifest.json
CHANGED