@skuba-lib/api 2.3.0-rolldown-cdk-bundle-plugin-20260804001207 → 2.3.0-rolldown-cdk-bundle-plugin-20260804050549
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/lib/fs-BBMaW7WT.cjs +21 -0
- package/lib/fs-BrQNZY8y.mjs +14 -0
- package/lib/git/index.cjs +1 -1
- package/lib/git/index.mjs +1 -1
- package/lib/{git-BeGqD0KV.cjs → git-BGcWTYZJ.cjs} +2 -13
- package/lib/{git-DyhV01cl.mjs → git-DKqd7R1V.mjs} +1 -12
- package/lib/github/index.cjs +2 -2
- package/lib/github/index.mjs +2 -2
- package/lib/{github-C91l-j0Z.cjs → github-B2fQutQz.cjs} +1 -1
- package/lib/{github-CmHDTIHw.mjs → github-EDhl9ON9.mjs} +1 -1
- package/lib/index-J1Qqgryi.d.cts +94 -0
- package/lib/index-J1Qqgryi.d.mts +94 -0
- package/lib/index.cjs +9 -2
- package/lib/index.d.cts +2 -1
- package/lib/index.d.mts +2 -1
- package/lib/index.mjs +4 -3
- package/lib/rolldown/index.cjs +3 -0
- package/lib/rolldown/index.d.cts +2 -0
- package/lib/rolldown/index.d.mts +2 -0
- package/lib/rolldown/index.mjs +2 -0
- package/lib/rolldown-08iefo1V.mjs +237 -0
- package/lib/rolldown-CbJyS-Uy.cjs +250 -0
- package/package.json +17 -2
- package/rolldown/package.json +6 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-DakpK96I.cjs");
|
|
2
|
+
const require_error = require("./error-BSBcaHO0.cjs");
|
|
3
|
+
let fs_extra = require("fs-extra");
|
|
4
|
+
fs_extra = require_rolldown_runtime.__toESM(fs_extra, 1);
|
|
5
|
+
//#region ../../src/utils/fs.ts
|
|
6
|
+
const pathExists = async (filePath) => {
|
|
7
|
+
try {
|
|
8
|
+
await fs_extra.default.promises.access(filePath);
|
|
9
|
+
return true;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
if (require_error.isErrorWithCode(error, "ENOENT")) return false;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
Object.defineProperty(exports, "pathExists", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function() {
|
|
19
|
+
return pathExists;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { t as isErrorWithCode } from "./error-CxiNRw9A.mjs";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
//#region ../../src/utils/fs.ts
|
|
4
|
+
const pathExists = async (filePath) => {
|
|
5
|
+
try {
|
|
6
|
+
await fs.promises.access(filePath);
|
|
7
|
+
return true;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
if (isErrorWithCode(error, "ENOENT")) return false;
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { pathExists as t };
|
package/lib/git/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_git = require("../git-
|
|
2
|
+
const require_git = require("../git-BGcWTYZJ.cjs");
|
|
3
3
|
exports.commit = require_git.commit;
|
|
4
4
|
exports.commitAllChanges = require_git.commitAllChanges;
|
|
5
5
|
exports.currentBranch = require_git.currentBranch;
|
package/lib/git/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as push, d as getHeadCommitMessage, f as currentBranch, g as commit, h as findRoot, i as fastForwardBranch, l as getOwnerAndRepo, m as getChangedFiles, n as isFileGitIgnored, p as commitAllChanges, r as reset, u as getHeadCommitId } from "../git-
|
|
1
|
+
import { a as push, d as getHeadCommitMessage, f as currentBranch, g as commit, h as findRoot, i as fastForwardBranch, l as getOwnerAndRepo, m as getChangedFiles, n as isFileGitIgnored, p as commitAllChanges, r as reset, u as getHeadCommitId } from "../git-DKqd7R1V.mjs";
|
|
2
2
|
export { commit, commitAllChanges, currentBranch, fastForwardBranch, findRoot, getChangedFiles, getHeadCommitId, getHeadCommitMessage, getOwnerAndRepo, isFileGitIgnored, push, reset };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-DakpK96I.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_fs = require("./fs-BBMaW7WT.cjs");
|
|
3
3
|
let fs_extra = require("fs-extra");
|
|
4
4
|
fs_extra = require_rolldown_runtime.__toESM(fs_extra, 1);
|
|
5
5
|
let isomorphic_git = require("isomorphic-git");
|
|
@@ -39,17 +39,6 @@ const findRoot$1 = async ({ dir }) => {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
//#endregion
|
|
42
|
-
//#region ../../src/utils/fs.ts
|
|
43
|
-
const pathExists = async (filePath) => {
|
|
44
|
-
try {
|
|
45
|
-
await fs_extra.default.promises.access(filePath);
|
|
46
|
-
return true;
|
|
47
|
-
} catch (error) {
|
|
48
|
-
if (require_error.isErrorWithCode(error, "ENOENT")) return false;
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
//#endregion
|
|
53
42
|
//#region src/git/getChangedFiles.ts
|
|
54
43
|
const mapState = (row) => {
|
|
55
44
|
if (row[1] === 0) return "added";
|
|
@@ -140,7 +129,7 @@ const getChangedFilesFromRefs = async ({ dir, src, dst }) => {
|
|
|
140
129
|
const createIsLfsFilter = async (gitRoot) => {
|
|
141
130
|
if (!gitRoot) return () => false;
|
|
142
131
|
const lfsFile = `${gitRoot}/.gitattributes`;
|
|
143
|
-
if (!await pathExists(lfsFile)) return () => false;
|
|
132
|
+
if (!await require_fs.pathExists(lfsFile)) return () => false;
|
|
144
133
|
const filter = (0, ignore.default)().add((await fs_extra.default.promises.readFile(lfsFile, "utf8")).split("\n").map((l) => l.trim()).filter((l) => !l.startsWith("#") && l.includes("filter=lfs")).map((l) => l.split(/\s+/)[0]).flatMap((l) => l ? [l] : []));
|
|
145
134
|
return (pathname) => filter.ignores(pathname);
|
|
146
135
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { t as
|
|
2
|
+
import { t as pathExists } from "./fs-BrQNZY8y.mjs";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import git, { findRoot } from "isomorphic-git";
|
|
5
5
|
import path from "path";
|
|
@@ -34,17 +34,6 @@ const findRoot$1 = async ({ dir }) => {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
//#endregion
|
|
37
|
-
//#region ../../src/utils/fs.ts
|
|
38
|
-
const pathExists = async (filePath) => {
|
|
39
|
-
try {
|
|
40
|
-
await fs.promises.access(filePath);
|
|
41
|
-
return true;
|
|
42
|
-
} catch (error) {
|
|
43
|
-
if (isErrorWithCode(error, "ENOENT")) return false;
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
//#endregion
|
|
48
37
|
//#region src/git/getChangedFiles.ts
|
|
49
38
|
const mapState = (row) => {
|
|
50
39
|
if (row[1] === 0) return "added";
|
package/lib/github/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_git = require("../git-
|
|
3
|
-
const require_github = require("../github-
|
|
2
|
+
const require_git = require("../git-BGcWTYZJ.cjs");
|
|
3
|
+
const require_github = require("../github-B2fQutQz.cjs");
|
|
4
4
|
exports.apiTokenFromEnvironment = require_git.apiTokenFromEnvironment;
|
|
5
5
|
exports.buildNameFromEnvironment = require_git.buildNameFromEnvironment;
|
|
6
6
|
exports.createCheckRun = require_github.createCheckRun;
|
package/lib/github/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { c as enabledFromEnvironment, o as apiTokenFromEnvironment, s as buildNameFromEnvironment } from "../git-
|
|
2
|
-
import { a as putIssueComment, i as uploadFileChanges, n as readFileChanges, o as getPullRequestNumber, r as uploadAllFileChanges, s as createCheckRun } from "../github-
|
|
1
|
+
import { c as enabledFromEnvironment, o as apiTokenFromEnvironment, s as buildNameFromEnvironment } from "../git-DKqd7R1V.mjs";
|
|
2
|
+
import { a as putIssueComment, i as uploadFileChanges, n as readFileChanges, o as getPullRequestNumber, r as uploadAllFileChanges, s as createCheckRun } from "../github-EDhl9ON9.mjs";
|
|
3
3
|
export { apiTokenFromEnvironment, buildNameFromEnvironment, createCheckRun, enabledFromEnvironment, getPullRequestNumber, putIssueComment, readFileChanges, uploadAllFileChanges, uploadFileChanges };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-DakpK96I.cjs");
|
|
2
2
|
const require_logging = require("./logging-BqpzZfsF.cjs");
|
|
3
|
-
const require_git = require("./git-
|
|
3
|
+
const require_git = require("./git-BGcWTYZJ.cjs");
|
|
4
4
|
let fs_extra = require("fs-extra");
|
|
5
5
|
fs_extra = require_rolldown_runtime.__toESM(fs_extra, 1);
|
|
6
6
|
let path = require("path");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { n as pluralise } from "./logging-BQNEupxh.mjs";
|
|
3
|
-
import { c as enabledFromEnvironment, h as findRoot, i as fastForwardBranch, l as getOwnerAndRepo, m as getChangedFiles, o as apiTokenFromEnvironment, s as buildNameFromEnvironment, u as getHeadCommitId } from "./git-
|
|
3
|
+
import { c as enabledFromEnvironment, h as findRoot, i as fastForwardBranch, l as getOwnerAndRepo, m as getChangedFiles, o as apiTokenFromEnvironment, s as buildNameFromEnvironment, u as getHeadCommitId } from "./git-DKqd7R1V.mjs";
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
import path from "path";
|
|
6
6
|
//#region src/github/octokit.ts
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Plugin } from "rolldown";
|
|
2
|
+
//#region src/rolldown/lambdaAsset.d.ts
|
|
3
|
+
interface LambdaAssetFile {
|
|
4
|
+
/**
|
|
5
|
+
* Path to the file or directory to copy, resolved relative to `projectRoot`.
|
|
6
|
+
*/
|
|
7
|
+
from: string;
|
|
8
|
+
/**
|
|
9
|
+
* Destination path relative to the output directory.
|
|
10
|
+
*
|
|
11
|
+
* Defaults to the basename of `from`, placing it at the top of the output
|
|
12
|
+
* directory.
|
|
13
|
+
*/
|
|
14
|
+
to?: string;
|
|
15
|
+
}
|
|
16
|
+
interface LambdaAssetOptions {
|
|
17
|
+
/**
|
|
18
|
+
* npm packages to install into the output directory rather than embed in the
|
|
19
|
+
* bundle.
|
|
20
|
+
*
|
|
21
|
+
* Versions are resolved from the copy installed under `projectRoot`. Mark
|
|
22
|
+
* these packages `external` in your rolldown config too, otherwise they will
|
|
23
|
+
* be bundled _and_ installed.
|
|
24
|
+
*
|
|
25
|
+
* Packages with native binaries (e.g. `sharp`) are the usual candidates.
|
|
26
|
+
*/
|
|
27
|
+
nodeModules?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Extra files or directories to copy into the output directory alongside the
|
|
30
|
+
* bundle, e.g. static assets or configuration the handler reads at runtime.
|
|
31
|
+
*
|
|
32
|
+
* Each `from` is resolved relative to `projectRoot`; each `to` defaults to
|
|
33
|
+
* the basename of `from` and is resolved relative to the output directory.
|
|
34
|
+
*/
|
|
35
|
+
assets?: LambdaAssetFile[];
|
|
36
|
+
/**
|
|
37
|
+
* Directory that `nodeModules` versions are resolved from, and that `assets`
|
|
38
|
+
* are copied from.
|
|
39
|
+
*
|
|
40
|
+
* This is the directory holding the `package.json` that depends on them; in a
|
|
41
|
+
* workspace, that is the individual package rather than the workspace root.
|
|
42
|
+
*
|
|
43
|
+
* Defaults to `process.cwd()`.
|
|
44
|
+
*/
|
|
45
|
+
projectRoot?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Path to the `pnpm-lock.yaml` to install against.
|
|
48
|
+
*
|
|
49
|
+
* pnpm keeps this at the workspace root, so its directory is also where the
|
|
50
|
+
* workspace config and patches are staged from.
|
|
51
|
+
*
|
|
52
|
+
* Defaults to the nearest lock file, walking up from `process.cwd()`.
|
|
53
|
+
*/
|
|
54
|
+
depsLockFilePath?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Prepares a rolldown output directory for deployment as a Lambda asset.
|
|
58
|
+
*
|
|
59
|
+
* The plugin supports ESM output and pnpm only. It makes no assumptions about
|
|
60
|
+
* how you bundle; it only augments what rolldown has already written:
|
|
61
|
+
*
|
|
62
|
+
* 1. Writes a `package.json` of `type: 'module'`.
|
|
63
|
+
* 2. Installs `nodeModules` into the output directory with pnpm, staging the
|
|
64
|
+
* workspace config, `.npmrc`, lock file and patches to do so.
|
|
65
|
+
* 3. Strips those install-only files back out, leaving the bundle, the
|
|
66
|
+
* generated `package.json` and `node_modules`.
|
|
67
|
+
* 4. Copies any extra `assets` into the output directory alongside the bundle.
|
|
68
|
+
*
|
|
69
|
+
* The result can be handed to CDK as `aws_lambda.Code.fromAsset(outputDir)`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```js
|
|
73
|
+
* // rolldown.config.mjs
|
|
74
|
+
* import { Rolldown } from 'skuba';
|
|
75
|
+
*
|
|
76
|
+
* export default {
|
|
77
|
+
* input: 'src/lambda.ts',
|
|
78
|
+
* output: { dir: 'lib' },
|
|
79
|
+
* external: ['sharp'],
|
|
80
|
+
* plugins: [
|
|
81
|
+
* Rolldown.lambdaAsset({
|
|
82
|
+
* nodeModules: ['sharp'],
|
|
83
|
+
* assets: [{ from: 'src/config.json' }],
|
|
84
|
+
* }),
|
|
85
|
+
* ],
|
|
86
|
+
* };
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare const lambdaAsset: ({ nodeModules, assets, projectRoot: projectRootOption, depsLockFilePath: depsLockFilePathOption }?: LambdaAssetOptions) => Plugin;
|
|
90
|
+
declare namespace index_d_exports {
|
|
91
|
+
export { LambdaAssetFile, LambdaAssetOptions, lambdaAsset };
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { lambdaAsset as i, LambdaAssetFile as n, LambdaAssetOptions as r, index_d_exports as t };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Plugin } from "rolldown";
|
|
2
|
+
//#region src/rolldown/lambdaAsset.d.ts
|
|
3
|
+
interface LambdaAssetFile {
|
|
4
|
+
/**
|
|
5
|
+
* Path to the file or directory to copy, resolved relative to `projectRoot`.
|
|
6
|
+
*/
|
|
7
|
+
from: string;
|
|
8
|
+
/**
|
|
9
|
+
* Destination path relative to the output directory.
|
|
10
|
+
*
|
|
11
|
+
* Defaults to the basename of `from`, placing it at the top of the output
|
|
12
|
+
* directory.
|
|
13
|
+
*/
|
|
14
|
+
to?: string;
|
|
15
|
+
}
|
|
16
|
+
interface LambdaAssetOptions {
|
|
17
|
+
/**
|
|
18
|
+
* npm packages to install into the output directory rather than embed in the
|
|
19
|
+
* bundle.
|
|
20
|
+
*
|
|
21
|
+
* Versions are resolved from the copy installed under `projectRoot`. Mark
|
|
22
|
+
* these packages `external` in your rolldown config too, otherwise they will
|
|
23
|
+
* be bundled _and_ installed.
|
|
24
|
+
*
|
|
25
|
+
* Packages with native binaries (e.g. `sharp`) are the usual candidates.
|
|
26
|
+
*/
|
|
27
|
+
nodeModules?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Extra files or directories to copy into the output directory alongside the
|
|
30
|
+
* bundle, e.g. static assets or configuration the handler reads at runtime.
|
|
31
|
+
*
|
|
32
|
+
* Each `from` is resolved relative to `projectRoot`; each `to` defaults to
|
|
33
|
+
* the basename of `from` and is resolved relative to the output directory.
|
|
34
|
+
*/
|
|
35
|
+
assets?: LambdaAssetFile[];
|
|
36
|
+
/**
|
|
37
|
+
* Directory that `nodeModules` versions are resolved from, and that `assets`
|
|
38
|
+
* are copied from.
|
|
39
|
+
*
|
|
40
|
+
* This is the directory holding the `package.json` that depends on them; in a
|
|
41
|
+
* workspace, that is the individual package rather than the workspace root.
|
|
42
|
+
*
|
|
43
|
+
* Defaults to `process.cwd()`.
|
|
44
|
+
*/
|
|
45
|
+
projectRoot?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Path to the `pnpm-lock.yaml` to install against.
|
|
48
|
+
*
|
|
49
|
+
* pnpm keeps this at the workspace root, so its directory is also where the
|
|
50
|
+
* workspace config and patches are staged from.
|
|
51
|
+
*
|
|
52
|
+
* Defaults to the nearest lock file, walking up from `process.cwd()`.
|
|
53
|
+
*/
|
|
54
|
+
depsLockFilePath?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Prepares a rolldown output directory for deployment as a Lambda asset.
|
|
58
|
+
*
|
|
59
|
+
* The plugin supports ESM output and pnpm only. It makes no assumptions about
|
|
60
|
+
* how you bundle; it only augments what rolldown has already written:
|
|
61
|
+
*
|
|
62
|
+
* 1. Writes a `package.json` of `type: 'module'`.
|
|
63
|
+
* 2. Installs `nodeModules` into the output directory with pnpm, staging the
|
|
64
|
+
* workspace config, `.npmrc`, lock file and patches to do so.
|
|
65
|
+
* 3. Strips those install-only files back out, leaving the bundle, the
|
|
66
|
+
* generated `package.json` and `node_modules`.
|
|
67
|
+
* 4. Copies any extra `assets` into the output directory alongside the bundle.
|
|
68
|
+
*
|
|
69
|
+
* The result can be handed to CDK as `aws_lambda.Code.fromAsset(outputDir)`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```js
|
|
73
|
+
* // rolldown.config.mjs
|
|
74
|
+
* import { Rolldown } from 'skuba';
|
|
75
|
+
*
|
|
76
|
+
* export default {
|
|
77
|
+
* input: 'src/lambda.ts',
|
|
78
|
+
* output: { dir: 'lib' },
|
|
79
|
+
* external: ['sharp'],
|
|
80
|
+
* plugins: [
|
|
81
|
+
* Rolldown.lambdaAsset({
|
|
82
|
+
* nodeModules: ['sharp'],
|
|
83
|
+
* assets: [{ from: 'src/config.json' }],
|
|
84
|
+
* }),
|
|
85
|
+
* ],
|
|
86
|
+
* };
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare const lambdaAsset: ({ nodeModules, assets, projectRoot: projectRootOption, depsLockFilePath: depsLockFilePathOption }?: LambdaAssetOptions) => Plugin;
|
|
90
|
+
declare namespace index_d_exports {
|
|
91
|
+
export { LambdaAssetFile, LambdaAssetOptions, lambdaAsset };
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
export { lambdaAsset as i, LambdaAssetFile as n, LambdaAssetOptions as r, index_d_exports as t };
|
package/lib/index.cjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_buildkite = require("./buildkite-CM-xlOq5.cjs");
|
|
3
3
|
const require_cdk_index = require("./cdk/index.cjs");
|
|
4
|
-
const require_git = require("./git-
|
|
5
|
-
const require_github = require("./github-
|
|
4
|
+
const require_git = require("./git-BGcWTYZJ.cjs");
|
|
5
|
+
const require_github = require("./github-B2fQutQz.cjs");
|
|
6
6
|
const require_net = require("./net-zrteIHld.cjs");
|
|
7
|
+
const require_rolldown = require("./rolldown-CbJyS-Uy.cjs");
|
|
7
8
|
Object.defineProperty(exports, "Buildkite", {
|
|
8
9
|
enumerable: true,
|
|
9
10
|
get: function() {
|
|
@@ -34,3 +35,9 @@ Object.defineProperty(exports, "Net", {
|
|
|
34
35
|
return require_net.net_exports;
|
|
35
36
|
}
|
|
36
37
|
});
|
|
38
|
+
Object.defineProperty(exports, "Rolldown", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function() {
|
|
41
|
+
return require_rolldown.rolldown_exports;
|
|
42
|
+
}
|
|
43
|
+
});
|
package/lib/index.d.cts
CHANGED
|
@@ -3,4 +3,5 @@ import { t as index_d_exports$1 } from "./cdk/index.cjs";
|
|
|
3
3
|
import { t as index_d_exports$2 } from "./index-CLEYcnJY.cjs";
|
|
4
4
|
import { t as index_d_exports$3 } from "./index-CPm5rAMy.cjs";
|
|
5
5
|
import { t as index_d_exports$4 } from "./index-C9lVo3vU.cjs";
|
|
6
|
-
|
|
6
|
+
import { t as index_d_exports$5 } from "./index-J1Qqgryi.cjs";
|
|
7
|
+
export { index_d_exports as Buildkite, index_d_exports$1 as Cdk, index_d_exports$2 as Git, index_d_exports$3 as GitHub, index_d_exports$4 as Net, index_d_exports$5 as Rolldown };
|
package/lib/index.d.mts
CHANGED
|
@@ -3,4 +3,5 @@ import { t as index_d_exports$1 } from "./cdk/index.mjs";
|
|
|
3
3
|
import { t as index_d_exports$2 } from "./index-CLEYcnJY.mjs";
|
|
4
4
|
import { t as index_d_exports$3 } from "./index-CwdiFn_m.mjs";
|
|
5
5
|
import { t as index_d_exports$4 } from "./index-C9lVo3vU.mjs";
|
|
6
|
-
|
|
6
|
+
import { t as index_d_exports$5 } from "./index-J1Qqgryi.mjs";
|
|
7
|
+
export { index_d_exports as Buildkite, index_d_exports$1 as Cdk, index_d_exports$2 as Git, index_d_exports$3 as GitHub, index_d_exports$4 as Net, index_d_exports$5 as Rolldown };
|
package/lib/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as buildkite_exports } from "./buildkite-B0gyBRNS.mjs";
|
|
2
2
|
import { t as cdk_exports } from "./cdk/index.mjs";
|
|
3
|
-
import { t as git_exports } from "./git-
|
|
4
|
-
import { t as github_exports } from "./github-
|
|
3
|
+
import { t as git_exports } from "./git-DKqd7R1V.mjs";
|
|
4
|
+
import { t as github_exports } from "./github-EDhl9ON9.mjs";
|
|
5
5
|
import { t as net_exports } from "./net-97EvMPiP.mjs";
|
|
6
|
-
|
|
6
|
+
import { t as rolldown_exports } from "./rolldown-08iefo1V.mjs";
|
|
7
|
+
export { buildkite_exports as Buildkite, cdk_exports as Cdk, git_exports as Git, github_exports as GitHub, net_exports as Net, rolldown_exports as Rolldown };
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { t as log } from "./logging-BQNEupxh.mjs";
|
|
3
|
+
import { t as createExec } from "./exec-Dp89sakg.mjs";
|
|
4
|
+
import { t as pathExists } from "./fs-BrQNZY8y.mjs";
|
|
5
|
+
import { findPackageJSON } from "node:module";
|
|
6
|
+
import fs from "fs-extra";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import { findUp } from "find-up";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { parse, stringify } from "yaml";
|
|
11
|
+
//#region src/rolldown/pnpm.ts
|
|
12
|
+
const PNPM_LOCK = "pnpm-lock.yaml";
|
|
13
|
+
const PNPM_WORKSPACE_YAML = "pnpm-workspace.yaml";
|
|
14
|
+
const PNPM_PATCHES_DIR = "patches";
|
|
15
|
+
const PNPM_WORKSPACE_FILES = [
|
|
16
|
+
PNPM_WORKSPACE_YAML,
|
|
17
|
+
".npmrc",
|
|
18
|
+
".pnpmfile.cjs",
|
|
19
|
+
".pnpmfile.mjs"
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Files that `pnpm install` leaves behind which record machine-local paths and
|
|
23
|
+
* timestamps, and so would churn the CDK asset hash on every build.
|
|
24
|
+
*/
|
|
25
|
+
const PNPM_METADATA_FILES = [path.join("node_modules", ".modules.yaml"), path.join("node_modules", ".pnpm-workspace-state-v1.json")];
|
|
26
|
+
const PNPM_INSTALL_COMMAND = [
|
|
27
|
+
"pnpm",
|
|
28
|
+
"install",
|
|
29
|
+
"--config.node-linker=hoisted",
|
|
30
|
+
"--config.package-import-method=clone-or-copy",
|
|
31
|
+
"--no-frozen-lockfile"
|
|
32
|
+
];
|
|
33
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
+
const parseJsonFile = async (filePath) => {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(await fs.promises.readFile(filePath, "utf-8"));
|
|
37
|
+
} catch (err) {
|
|
38
|
+
throw new Error(`Failed to parse ${filePath} as JSON: ${err.message}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Reads the `packageManager` pin from the workspace root manifest.
|
|
43
|
+
*
|
|
44
|
+
* Forwarding it to the output directory keeps the staged install on the same
|
|
45
|
+
* pnpm version as the project.
|
|
46
|
+
*/
|
|
47
|
+
const readPackageManagerField = async (workspaceRoot) => {
|
|
48
|
+
const pkgPath = path.join(workspaceRoot, "package.json");
|
|
49
|
+
if (!await pathExists(pkgPath)) return;
|
|
50
|
+
const parsed = await parseJsonFile(pkgPath);
|
|
51
|
+
return isRecord(parsed) && typeof parsed.packageManager === "string" ? parsed.packageManager : void 0;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The output directory installs a subset of the workspace's dependencies, so
|
|
55
|
+
* most `patchedDependencies` entries have nothing to apply to. pnpm fails the
|
|
56
|
+
* install on an unused patch unless this is set.
|
|
57
|
+
*/
|
|
58
|
+
const allowUnusedPatches = (content) => {
|
|
59
|
+
let doc;
|
|
60
|
+
try {
|
|
61
|
+
doc = parse(content);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
throw new Error(`Failed to parse ${PNPM_WORKSPACE_YAML}: ${err.message}`);
|
|
64
|
+
}
|
|
65
|
+
if (!isRecord(doc)) return content;
|
|
66
|
+
doc.allowUnusedPatches = true;
|
|
67
|
+
return stringify(doc);
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Stages the pnpm config that an install in `outputDir` needs.
|
|
71
|
+
*
|
|
72
|
+
* Patch files are staged from `patches`, where `pnpm patch-commit` writes them.
|
|
73
|
+
*
|
|
74
|
+
* Every path written is appended to `stagedFiles` so the caller can strip it
|
|
75
|
+
* back out once the install is done; `.npmrc` in particular may hold registry
|
|
76
|
+
* credentials that must not ship in the asset.
|
|
77
|
+
*/
|
|
78
|
+
const stageWorkspaceFiles = async (workspaceRoot, outputDir, stagedFiles = []) => {
|
|
79
|
+
for (const file of PNPM_WORKSPACE_FILES) {
|
|
80
|
+
const src = path.join(workspaceRoot, file);
|
|
81
|
+
if (!await pathExists(src)) continue;
|
|
82
|
+
const dest = path.join(outputDir, file);
|
|
83
|
+
if (file === PNPM_WORKSPACE_YAML) await fs.promises.writeFile(dest, allowUnusedPatches(await fs.promises.readFile(src, "utf8")));
|
|
84
|
+
else await fs.promises.copyFile(src, dest);
|
|
85
|
+
stagedFiles.push(dest);
|
|
86
|
+
}
|
|
87
|
+
const patchesSrc = path.join(workspaceRoot, PNPM_PATCHES_DIR);
|
|
88
|
+
if (await pathExists(patchesSrc)) {
|
|
89
|
+
const patchesDest = path.join(outputDir, PNPM_PATCHES_DIR);
|
|
90
|
+
await fs.copy(patchesSrc, patchesDest);
|
|
91
|
+
stagedFiles.push(patchesDest);
|
|
92
|
+
}
|
|
93
|
+
return stagedFiles;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Resolves the installed version of each module, as seen from `resolveFrom`.
|
|
97
|
+
*/
|
|
98
|
+
const extractDependencies = async (resolveFrom, modules) => {
|
|
99
|
+
const result = {};
|
|
100
|
+
const base = pathToFileURL(resolveFrom);
|
|
101
|
+
for (const mod of modules) {
|
|
102
|
+
let modPkgPath;
|
|
103
|
+
try {
|
|
104
|
+
modPkgPath = findPackageJSON(mod, base);
|
|
105
|
+
} catch {
|
|
106
|
+
modPkgPath = void 0;
|
|
107
|
+
}
|
|
108
|
+
const parsed = modPkgPath ? await parseJsonFile(modPkgPath) : void 0;
|
|
109
|
+
const version = isRecord(parsed) && typeof parsed.version === "string" ? parsed.version.trim() : void 0;
|
|
110
|
+
if (!version) throw new Error(`Cannot extract version for module '${mod}'. Check that it's referenced in your package.json or installed.`);
|
|
111
|
+
result[mod] = version;
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/rolldown/lambdaAsset.ts
|
|
117
|
+
const PLUGIN_NAME = "skuba:lambda-asset";
|
|
118
|
+
const resolveOutputDir = ({ dir, file }) => {
|
|
119
|
+
if (!dir) throw new Error(`${PLUGIN_NAME} requires \`output.dir\`; it prepares a deployable directory, so a single \`output.file\`${file ? ` (${file})` : ""} has nowhere to install into.`);
|
|
120
|
+
return path.resolve(dir);
|
|
121
|
+
};
|
|
122
|
+
const resolveLockFile = async (depsLockFilePath) => {
|
|
123
|
+
if (!depsLockFilePath) return findUp(PNPM_LOCK);
|
|
124
|
+
const resolved = path.resolve(depsLockFilePath);
|
|
125
|
+
if (!await pathExists(resolved)) throw new Error(`${PLUGIN_NAME} cannot find a ${PNPM_LOCK} at '${depsLockFilePath}'.`);
|
|
126
|
+
return resolved;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Copies extra `assets` into the output directory alongside the bundle.
|
|
130
|
+
*
|
|
131
|
+
* `from` is resolved relative to `projectRoot`, and `to` relative to the
|
|
132
|
+
* output directory, creating parent directories as needed. Directories are
|
|
133
|
+
* copied recursively.
|
|
134
|
+
*/
|
|
135
|
+
const copyAssets = async (outputDir, projectRoot, assets) => {
|
|
136
|
+
for (const asset of assets) {
|
|
137
|
+
const from = path.resolve(projectRoot, asset.from);
|
|
138
|
+
const to = path.join(outputDir, asset.to ?? path.basename(asset.from));
|
|
139
|
+
await fs.ensureDir(path.dirname(to));
|
|
140
|
+
await fs.copy(from, to);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const writeOutputPackageJson = (outputDir, fields = {}) => fs.promises.writeFile(path.join(outputDir, "package.json"), JSON.stringify({
|
|
144
|
+
type: "module",
|
|
145
|
+
...fields
|
|
146
|
+
}, null, 2));
|
|
147
|
+
/**
|
|
148
|
+
* Strips the install-only files back out of the output directory.
|
|
149
|
+
*
|
|
150
|
+
* `.npmrc` may hold registry credentials, so one path failing to remove must
|
|
151
|
+
* not skip the rest, and the caller must hear about it.
|
|
152
|
+
*/
|
|
153
|
+
const stripInstallFiles = async (outputDir, stagedFiles, cause) => {
|
|
154
|
+
const reasons = (await Promise.allSettled([...stagedFiles, ...PNPM_METADATA_FILES.map((file) => path.join(outputDir, file))].map((file) => fs.remove(file)))).flatMap((result) => result.status === "rejected" ? [String(result.reason)] : []);
|
|
155
|
+
if (reasons.length) throw new Error(`${PLUGIN_NAME} could not strip install-only files from '${outputDir}'; these may include registry credentials and must not be deployed. ${reasons.join("; ")}`, { cause });
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Prepares a rolldown output directory for deployment as a Lambda asset.
|
|
159
|
+
*
|
|
160
|
+
* The plugin supports ESM output and pnpm only. It makes no assumptions about
|
|
161
|
+
* how you bundle; it only augments what rolldown has already written:
|
|
162
|
+
*
|
|
163
|
+
* 1. Writes a `package.json` of `type: 'module'`.
|
|
164
|
+
* 2. Installs `nodeModules` into the output directory with pnpm, staging the
|
|
165
|
+
* workspace config, `.npmrc`, lock file and patches to do so.
|
|
166
|
+
* 3. Strips those install-only files back out, leaving the bundle, the
|
|
167
|
+
* generated `package.json` and `node_modules`.
|
|
168
|
+
* 4. Copies any extra `assets` into the output directory alongside the bundle.
|
|
169
|
+
*
|
|
170
|
+
* The result can be handed to CDK as `aws_lambda.Code.fromAsset(outputDir)`.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```js
|
|
174
|
+
* // rolldown.config.mjs
|
|
175
|
+
* import { Rolldown } from 'skuba';
|
|
176
|
+
*
|
|
177
|
+
* export default {
|
|
178
|
+
* input: 'src/lambda.ts',
|
|
179
|
+
* output: { dir: 'lib' },
|
|
180
|
+
* external: ['sharp'],
|
|
181
|
+
* plugins: [
|
|
182
|
+
* Rolldown.lambdaAsset({
|
|
183
|
+
* nodeModules: ['sharp'],
|
|
184
|
+
* assets: [{ from: 'src/config.json' }],
|
|
185
|
+
* }),
|
|
186
|
+
* ],
|
|
187
|
+
* };
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
const lambdaAsset = ({ nodeModules = [], assets = [], projectRoot: projectRootOption, depsLockFilePath: depsLockFilePathOption } = {}) => {
|
|
191
|
+
const prepared = /* @__PURE__ */ new Set();
|
|
192
|
+
return {
|
|
193
|
+
name: PLUGIN_NAME,
|
|
194
|
+
buildStart() {
|
|
195
|
+
prepared.clear();
|
|
196
|
+
},
|
|
197
|
+
async writeBundle(outputOptions) {
|
|
198
|
+
const outputDir = resolveOutputDir(outputOptions);
|
|
199
|
+
if (prepared.has(outputDir)) return;
|
|
200
|
+
prepared.add(outputDir);
|
|
201
|
+
const projectRoot = path.resolve(projectRootOption ?? process.cwd());
|
|
202
|
+
await copyAssets(outputDir, projectRoot, assets);
|
|
203
|
+
if (!nodeModules.length) {
|
|
204
|
+
await writeOutputPackageJson(outputDir);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const depsLockFilePath = await resolveLockFile(depsLockFilePathOption);
|
|
208
|
+
if (!depsLockFilePath) throw new Error(`${PLUGIN_NAME} cannot find a ${PNPM_LOCK}, which \`nodeModules\` requires. Specify one with \`depsLockFilePath\`.`);
|
|
209
|
+
const workspaceRoot = path.dirname(depsLockFilePath);
|
|
210
|
+
const projectPackageJson = path.join(projectRoot, "package.json");
|
|
211
|
+
if (!await pathExists(projectPackageJson)) throw new Error(`${PLUGIN_NAME} cannot find a package.json in '${projectRoot}', which \`nodeModules\` requires. Specify the directory with \`projectRoot\`.`);
|
|
212
|
+
await writeOutputPackageJson(outputDir, {
|
|
213
|
+
dependencies: await extractDependencies(projectPackageJson, nodeModules),
|
|
214
|
+
packageManager: await readPackageManagerField(workspaceRoot)
|
|
215
|
+
});
|
|
216
|
+
const stagedFiles = [];
|
|
217
|
+
try {
|
|
218
|
+
await stageWorkspaceFiles(workspaceRoot, outputDir, stagedFiles);
|
|
219
|
+
const lockDest = path.join(outputDir, PNPM_LOCK);
|
|
220
|
+
await fs.promises.copyFile(depsLockFilePath, lockDest);
|
|
221
|
+
stagedFiles.push(lockDest);
|
|
222
|
+
log.plain(log.bold(PLUGIN_NAME), "installing", log.bold(nodeModules.join(", ")));
|
|
223
|
+
const [bin, ...args] = PNPM_INSTALL_COMMAND;
|
|
224
|
+
await createExec({ cwd: outputDir })(bin, ...args);
|
|
225
|
+
} catch (err) {
|
|
226
|
+
await stripInstallFiles(outputDir, stagedFiles, err);
|
|
227
|
+
throw err;
|
|
228
|
+
}
|
|
229
|
+
await stripInstallFiles(outputDir, stagedFiles);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/rolldown/index.ts
|
|
235
|
+
var rolldown_exports = /* @__PURE__ */ __exportAll({ lambdaAsset: () => lambdaAsset });
|
|
236
|
+
//#endregion
|
|
237
|
+
export { lambdaAsset as n, rolldown_exports as t };
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-DakpK96I.cjs");
|
|
2
|
+
const require_logging = require("./logging-BqpzZfsF.cjs");
|
|
3
|
+
const require_exec = require("./exec-BGMWpmZ7.cjs");
|
|
4
|
+
const require_fs = require("./fs-BBMaW7WT.cjs");
|
|
5
|
+
let fs_extra = require("fs-extra");
|
|
6
|
+
fs_extra = require_rolldown_runtime.__toESM(fs_extra, 1);
|
|
7
|
+
let node_path = require("node:path");
|
|
8
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
9
|
+
let find_up = require("find-up");
|
|
10
|
+
let node_module = require("node:module");
|
|
11
|
+
let node_url = require("node:url");
|
|
12
|
+
let yaml = require("yaml");
|
|
13
|
+
//#region src/rolldown/pnpm.ts
|
|
14
|
+
const PNPM_LOCK = "pnpm-lock.yaml";
|
|
15
|
+
const PNPM_WORKSPACE_YAML = "pnpm-workspace.yaml";
|
|
16
|
+
const PNPM_PATCHES_DIR = "patches";
|
|
17
|
+
const PNPM_WORKSPACE_FILES = [
|
|
18
|
+
PNPM_WORKSPACE_YAML,
|
|
19
|
+
".npmrc",
|
|
20
|
+
".pnpmfile.cjs",
|
|
21
|
+
".pnpmfile.mjs"
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Files that `pnpm install` leaves behind which record machine-local paths and
|
|
25
|
+
* timestamps, and so would churn the CDK asset hash on every build.
|
|
26
|
+
*/
|
|
27
|
+
const PNPM_METADATA_FILES = [node_path.join("node_modules", ".modules.yaml"), node_path.join("node_modules", ".pnpm-workspace-state-v1.json")];
|
|
28
|
+
const PNPM_INSTALL_COMMAND = [
|
|
29
|
+
"pnpm",
|
|
30
|
+
"install",
|
|
31
|
+
"--config.node-linker=hoisted",
|
|
32
|
+
"--config.package-import-method=clone-or-copy",
|
|
33
|
+
"--no-frozen-lockfile"
|
|
34
|
+
];
|
|
35
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36
|
+
const parseJsonFile = async (filePath) => {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(await fs_extra.default.promises.readFile(filePath, "utf-8"));
|
|
39
|
+
} catch (err) {
|
|
40
|
+
throw new Error(`Failed to parse ${filePath} as JSON: ${err.message}`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Reads the `packageManager` pin from the workspace root manifest.
|
|
45
|
+
*
|
|
46
|
+
* Forwarding it to the output directory keeps the staged install on the same
|
|
47
|
+
* pnpm version as the project.
|
|
48
|
+
*/
|
|
49
|
+
const readPackageManagerField = async (workspaceRoot) => {
|
|
50
|
+
const pkgPath = node_path.join(workspaceRoot, "package.json");
|
|
51
|
+
if (!await require_fs.pathExists(pkgPath)) return;
|
|
52
|
+
const parsed = await parseJsonFile(pkgPath);
|
|
53
|
+
return isRecord(parsed) && typeof parsed.packageManager === "string" ? parsed.packageManager : void 0;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The output directory installs a subset of the workspace's dependencies, so
|
|
57
|
+
* most `patchedDependencies` entries have nothing to apply to. pnpm fails the
|
|
58
|
+
* install on an unused patch unless this is set.
|
|
59
|
+
*/
|
|
60
|
+
const allowUnusedPatches = (content) => {
|
|
61
|
+
let doc;
|
|
62
|
+
try {
|
|
63
|
+
doc = (0, yaml.parse)(content);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
throw new Error(`Failed to parse ${PNPM_WORKSPACE_YAML}: ${err.message}`);
|
|
66
|
+
}
|
|
67
|
+
if (!isRecord(doc)) return content;
|
|
68
|
+
doc.allowUnusedPatches = true;
|
|
69
|
+
return (0, yaml.stringify)(doc);
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Stages the pnpm config that an install in `outputDir` needs.
|
|
73
|
+
*
|
|
74
|
+
* Patch files are staged from `patches`, where `pnpm patch-commit` writes them.
|
|
75
|
+
*
|
|
76
|
+
* Every path written is appended to `stagedFiles` so the caller can strip it
|
|
77
|
+
* back out once the install is done; `.npmrc` in particular may hold registry
|
|
78
|
+
* credentials that must not ship in the asset.
|
|
79
|
+
*/
|
|
80
|
+
const stageWorkspaceFiles = async (workspaceRoot, outputDir, stagedFiles = []) => {
|
|
81
|
+
for (const file of PNPM_WORKSPACE_FILES) {
|
|
82
|
+
const src = node_path.join(workspaceRoot, file);
|
|
83
|
+
if (!await require_fs.pathExists(src)) continue;
|
|
84
|
+
const dest = node_path.join(outputDir, file);
|
|
85
|
+
if (file === PNPM_WORKSPACE_YAML) await fs_extra.default.promises.writeFile(dest, allowUnusedPatches(await fs_extra.default.promises.readFile(src, "utf8")));
|
|
86
|
+
else await fs_extra.default.promises.copyFile(src, dest);
|
|
87
|
+
stagedFiles.push(dest);
|
|
88
|
+
}
|
|
89
|
+
const patchesSrc = node_path.join(workspaceRoot, PNPM_PATCHES_DIR);
|
|
90
|
+
if (await require_fs.pathExists(patchesSrc)) {
|
|
91
|
+
const patchesDest = node_path.join(outputDir, PNPM_PATCHES_DIR);
|
|
92
|
+
await fs_extra.default.copy(patchesSrc, patchesDest);
|
|
93
|
+
stagedFiles.push(patchesDest);
|
|
94
|
+
}
|
|
95
|
+
return stagedFiles;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Resolves the installed version of each module, as seen from `resolveFrom`.
|
|
99
|
+
*/
|
|
100
|
+
const extractDependencies = async (resolveFrom, modules) => {
|
|
101
|
+
const result = {};
|
|
102
|
+
const base = (0, node_url.pathToFileURL)(resolveFrom);
|
|
103
|
+
for (const mod of modules) {
|
|
104
|
+
let modPkgPath;
|
|
105
|
+
try {
|
|
106
|
+
modPkgPath = (0, node_module.findPackageJSON)(mod, base);
|
|
107
|
+
} catch {
|
|
108
|
+
modPkgPath = void 0;
|
|
109
|
+
}
|
|
110
|
+
const parsed = modPkgPath ? await parseJsonFile(modPkgPath) : void 0;
|
|
111
|
+
const version = isRecord(parsed) && typeof parsed.version === "string" ? parsed.version.trim() : void 0;
|
|
112
|
+
if (!version) throw new Error(`Cannot extract version for module '${mod}'. Check that it's referenced in your package.json or installed.`);
|
|
113
|
+
result[mod] = version;
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
};
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/rolldown/lambdaAsset.ts
|
|
119
|
+
const PLUGIN_NAME = "skuba:lambda-asset";
|
|
120
|
+
const resolveOutputDir = ({ dir, file }) => {
|
|
121
|
+
if (!dir) throw new Error(`${PLUGIN_NAME} requires \`output.dir\`; it prepares a deployable directory, so a single \`output.file\`${file ? ` (${file})` : ""} has nowhere to install into.`);
|
|
122
|
+
return node_path.resolve(dir);
|
|
123
|
+
};
|
|
124
|
+
const resolveLockFile = async (depsLockFilePath) => {
|
|
125
|
+
if (!depsLockFilePath) return (0, find_up.findUp)(PNPM_LOCK);
|
|
126
|
+
const resolved = node_path.resolve(depsLockFilePath);
|
|
127
|
+
if (!await require_fs.pathExists(resolved)) throw new Error(`${PLUGIN_NAME} cannot find a ${PNPM_LOCK} at '${depsLockFilePath}'.`);
|
|
128
|
+
return resolved;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Copies extra `assets` into the output directory alongside the bundle.
|
|
132
|
+
*
|
|
133
|
+
* `from` is resolved relative to `projectRoot`, and `to` relative to the
|
|
134
|
+
* output directory, creating parent directories as needed. Directories are
|
|
135
|
+
* copied recursively.
|
|
136
|
+
*/
|
|
137
|
+
const copyAssets = async (outputDir, projectRoot, assets) => {
|
|
138
|
+
for (const asset of assets) {
|
|
139
|
+
const from = node_path.resolve(projectRoot, asset.from);
|
|
140
|
+
const to = node_path.join(outputDir, asset.to ?? node_path.basename(asset.from));
|
|
141
|
+
await fs_extra.default.ensureDir(node_path.dirname(to));
|
|
142
|
+
await fs_extra.default.copy(from, to);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const writeOutputPackageJson = (outputDir, fields = {}) => fs_extra.default.promises.writeFile(node_path.join(outputDir, "package.json"), JSON.stringify({
|
|
146
|
+
type: "module",
|
|
147
|
+
...fields
|
|
148
|
+
}, null, 2));
|
|
149
|
+
/**
|
|
150
|
+
* Strips the install-only files back out of the output directory.
|
|
151
|
+
*
|
|
152
|
+
* `.npmrc` may hold registry credentials, so one path failing to remove must
|
|
153
|
+
* not skip the rest, and the caller must hear about it.
|
|
154
|
+
*/
|
|
155
|
+
const stripInstallFiles = async (outputDir, stagedFiles, cause) => {
|
|
156
|
+
const reasons = (await Promise.allSettled([...stagedFiles, ...PNPM_METADATA_FILES.map((file) => node_path.join(outputDir, file))].map((file) => fs_extra.default.remove(file)))).flatMap((result) => result.status === "rejected" ? [String(result.reason)] : []);
|
|
157
|
+
if (reasons.length) throw new Error(`${PLUGIN_NAME} could not strip install-only files from '${outputDir}'; these may include registry credentials and must not be deployed. ${reasons.join("; ")}`, { cause });
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Prepares a rolldown output directory for deployment as a Lambda asset.
|
|
161
|
+
*
|
|
162
|
+
* The plugin supports ESM output and pnpm only. It makes no assumptions about
|
|
163
|
+
* how you bundle; it only augments what rolldown has already written:
|
|
164
|
+
*
|
|
165
|
+
* 1. Writes a `package.json` of `type: 'module'`.
|
|
166
|
+
* 2. Installs `nodeModules` into the output directory with pnpm, staging the
|
|
167
|
+
* workspace config, `.npmrc`, lock file and patches to do so.
|
|
168
|
+
* 3. Strips those install-only files back out, leaving the bundle, the
|
|
169
|
+
* generated `package.json` and `node_modules`.
|
|
170
|
+
* 4. Copies any extra `assets` into the output directory alongside the bundle.
|
|
171
|
+
*
|
|
172
|
+
* The result can be handed to CDK as `aws_lambda.Code.fromAsset(outputDir)`.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```js
|
|
176
|
+
* // rolldown.config.mjs
|
|
177
|
+
* import { Rolldown } from 'skuba';
|
|
178
|
+
*
|
|
179
|
+
* export default {
|
|
180
|
+
* input: 'src/lambda.ts',
|
|
181
|
+
* output: { dir: 'lib' },
|
|
182
|
+
* external: ['sharp'],
|
|
183
|
+
* plugins: [
|
|
184
|
+
* Rolldown.lambdaAsset({
|
|
185
|
+
* nodeModules: ['sharp'],
|
|
186
|
+
* assets: [{ from: 'src/config.json' }],
|
|
187
|
+
* }),
|
|
188
|
+
* ],
|
|
189
|
+
* };
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
const lambdaAsset = ({ nodeModules = [], assets = [], projectRoot: projectRootOption, depsLockFilePath: depsLockFilePathOption } = {}) => {
|
|
193
|
+
const prepared = /* @__PURE__ */ new Set();
|
|
194
|
+
return {
|
|
195
|
+
name: PLUGIN_NAME,
|
|
196
|
+
buildStart() {
|
|
197
|
+
prepared.clear();
|
|
198
|
+
},
|
|
199
|
+
async writeBundle(outputOptions) {
|
|
200
|
+
const outputDir = resolveOutputDir(outputOptions);
|
|
201
|
+
if (prepared.has(outputDir)) return;
|
|
202
|
+
prepared.add(outputDir);
|
|
203
|
+
const projectRoot = node_path.resolve(projectRootOption ?? process.cwd());
|
|
204
|
+
await copyAssets(outputDir, projectRoot, assets);
|
|
205
|
+
if (!nodeModules.length) {
|
|
206
|
+
await writeOutputPackageJson(outputDir);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const depsLockFilePath = await resolveLockFile(depsLockFilePathOption);
|
|
210
|
+
if (!depsLockFilePath) throw new Error(`${PLUGIN_NAME} cannot find a ${PNPM_LOCK}, which \`nodeModules\` requires. Specify one with \`depsLockFilePath\`.`);
|
|
211
|
+
const workspaceRoot = node_path.dirname(depsLockFilePath);
|
|
212
|
+
const projectPackageJson = node_path.join(projectRoot, "package.json");
|
|
213
|
+
if (!await require_fs.pathExists(projectPackageJson)) throw new Error(`${PLUGIN_NAME} cannot find a package.json in '${projectRoot}', which \`nodeModules\` requires. Specify the directory with \`projectRoot\`.`);
|
|
214
|
+
await writeOutputPackageJson(outputDir, {
|
|
215
|
+
dependencies: await extractDependencies(projectPackageJson, nodeModules),
|
|
216
|
+
packageManager: await readPackageManagerField(workspaceRoot)
|
|
217
|
+
});
|
|
218
|
+
const stagedFiles = [];
|
|
219
|
+
try {
|
|
220
|
+
await stageWorkspaceFiles(workspaceRoot, outputDir, stagedFiles);
|
|
221
|
+
const lockDest = node_path.join(outputDir, PNPM_LOCK);
|
|
222
|
+
await fs_extra.default.promises.copyFile(depsLockFilePath, lockDest);
|
|
223
|
+
stagedFiles.push(lockDest);
|
|
224
|
+
require_logging.log.plain(require_logging.log.bold(PLUGIN_NAME), "installing", require_logging.log.bold(nodeModules.join(", ")));
|
|
225
|
+
const [bin, ...args] = PNPM_INSTALL_COMMAND;
|
|
226
|
+
await require_exec.createExec({ cwd: outputDir })(bin, ...args);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
await stripInstallFiles(outputDir, stagedFiles, err);
|
|
229
|
+
throw err;
|
|
230
|
+
}
|
|
231
|
+
await stripInstallFiles(outputDir, stagedFiles);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/rolldown/index.ts
|
|
237
|
+
var rolldown_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ lambdaAsset: () => lambdaAsset });
|
|
238
|
+
//#endregion
|
|
239
|
+
Object.defineProperty(exports, "lambdaAsset", {
|
|
240
|
+
enumerable: true,
|
|
241
|
+
get: function() {
|
|
242
|
+
return lambdaAsset;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
Object.defineProperty(exports, "rolldown_exports", {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
get: function() {
|
|
248
|
+
return rolldown_exports;
|
|
249
|
+
}
|
|
250
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skuba-lib/api",
|
|
3
|
-
"version": "2.3.0-rolldown-cdk-bundle-plugin-
|
|
3
|
+
"version": "2.3.0-rolldown-cdk-bundle-plugin-20260804050549",
|
|
4
4
|
"description": "Node.js development API for skuba",
|
|
5
5
|
"homepage": "https://github.com/seek-oss/skuba#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
"import": "./lib/net/index.mjs",
|
|
40
40
|
"require": "./lib/net/index.cjs"
|
|
41
41
|
},
|
|
42
|
+
"./rolldown": {
|
|
43
|
+
"import": "./lib/rolldown/index.mjs",
|
|
44
|
+
"require": "./lib/rolldown/index.cjs"
|
|
45
|
+
},
|
|
42
46
|
"./package.json": "./package.json"
|
|
43
47
|
},
|
|
44
48
|
"main": "./lib/index.cjs",
|
|
@@ -50,7 +54,8 @@
|
|
|
50
54
|
"cdk",
|
|
51
55
|
"git",
|
|
52
56
|
"github",
|
|
53
|
-
"net"
|
|
57
|
+
"net",
|
|
58
|
+
"rolldown"
|
|
54
59
|
],
|
|
55
60
|
"dependencies": {
|
|
56
61
|
"@octokit/graphql": "^9.0.0",
|
|
@@ -58,13 +63,23 @@
|
|
|
58
63
|
"@octokit/types": "^16.0.0",
|
|
59
64
|
"concurrently": "^10.0.0",
|
|
60
65
|
"execa": "^9.6.1",
|
|
66
|
+
"find-up": "^8.0.0",
|
|
61
67
|
"fs-extra": "^11.0.0",
|
|
62
68
|
"ignore": "^7.0.0",
|
|
63
69
|
"isomorphic-git": "^1.37.6",
|
|
64
70
|
"npm-run-path": "^6.0.0",
|
|
65
71
|
"npm-which": "^3.0.1",
|
|
72
|
+
"yaml": "^2.9.0",
|
|
66
73
|
"zod": "^4.3.5"
|
|
67
74
|
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"rolldown": "^1.1.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"rolldown": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
68
83
|
"engines": {
|
|
69
84
|
"node": ">=22.14.0"
|
|
70
85
|
},
|