@solidactions/cli 3.32.0 → 3.33.0
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/dist/command-manifest.json +1 -1
- package/dist/commands/deploy.js +21 -3
- package/dist/utils/page-bundle.js +398 -0
- package/dist/utils/pages-sync.js +28 -2
- package/package.json +2 -1
package/dist/commands/deploy.js
CHANGED
|
@@ -527,6 +527,25 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
527
527
|
process.exit(1);
|
|
528
528
|
}
|
|
529
529
|
console.log(chalk_1.default.green('✓ Project structure validated'));
|
|
530
|
+
// Bundle tsx code pages before any project lookup or creation: a page
|
|
531
|
+
// that fails to bundle must not create a remote project (or sync
|
|
532
|
+
// anything); nothing is uploaded on this path. --config-only syncs
|
|
533
|
+
// YAML env declarations without building and never touches pages, so
|
|
534
|
+
// it skips bundling (a broken tsx page must not block a config-only
|
|
535
|
+
// sync); the empty map keeps the later payload call compiling on
|
|
536
|
+
// that path (unreachable after the early return below).
|
|
537
|
+
const pageFiles = (0, pages_sync_1.listCodePages)(yamlConfig ?? {});
|
|
538
|
+
let bundledPages = new Map();
|
|
539
|
+
if (!options.configOnly) {
|
|
540
|
+
const bundled = await (0, pages_sync_1.bundleCodePages)(sourceDir, pageFiles);
|
|
541
|
+
if (bundled.errors.length > 0) {
|
|
542
|
+
console.error(chalk_1.default.red('Page bundling failed; nothing was uploaded:'));
|
|
543
|
+
for (const line of bundled.errors)
|
|
544
|
+
console.error(chalk_1.default.red(line));
|
|
545
|
+
process.exit(1);
|
|
546
|
+
}
|
|
547
|
+
bundledPages = bundled.bundles;
|
|
548
|
+
}
|
|
530
549
|
// Check if the target environment's project record exists; create if needed.
|
|
531
550
|
// For production deploys where we already confirmed existence above, reuse
|
|
532
551
|
// the cached slug to avoid a duplicate GET.
|
|
@@ -629,10 +648,9 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
629
648
|
if (sourceMetadata && yamlConfig?.workflows) {
|
|
630
649
|
console.log(chalk_1.default.gray(`Revision to upload (client-reported): ${(0, source_provenance_1.formatRevisionSummary)(sourceMetadata)}`));
|
|
631
650
|
}
|
|
632
|
-
const pageFiles = (0, pages_sync_1.listCodePages)(yamlConfig ?? {});
|
|
633
651
|
let pageBodies;
|
|
634
652
|
try {
|
|
635
|
-
pageBodies = (0, pages_sync_1.readPageBodies)(sourceDir, pageFiles);
|
|
653
|
+
pageBodies = (0, pages_sync_1.readPageBodies)(sourceDir, pageFiles.filter(page => !bundledPages.has(page.slug)));
|
|
636
654
|
}
|
|
637
655
|
catch (error) {
|
|
638
656
|
console.error(chalk_1.default.red(`Failed to read page: ${error.message}`));
|
|
@@ -703,7 +721,7 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
703
721
|
console.log(line.startsWith('✓') ? chalk_1.default.green(line) : line);
|
|
704
722
|
}
|
|
705
723
|
yamlSyncFailed = yamlSyncFailed || appSummary.failed;
|
|
706
|
-
const payload = (0, pages_sync_1.buildPagesSyncPayload)(pageFiles, pageBodies, deploymentId, codeRef);
|
|
724
|
+
const payload = (0, pages_sync_1.buildPagesSyncPayload)(pageFiles, pageBodies, deploymentId, codeRef, bundledPages);
|
|
707
725
|
const result = await (0, pages_sync_1.syncPages)(config, projectSlug, payload);
|
|
708
726
|
const rows = result.body?.pages ?? [];
|
|
709
727
|
const trashed = result.body?.trashed ?? [];
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PageBundleError = exports.SOURCES_MAX_BYTES = exports.SOURCES_MAX_FILES = exports.COMPILED_LIMIT_BYTES = exports.PLATFORM_MODULES = void 0;
|
|
7
|
+
exports.assembleSources = assembleSources;
|
|
8
|
+
exports.readAdmitted = readAdmitted;
|
|
9
|
+
exports.bundlePage = bundlePage;
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const esbuild_1 = require("esbuild");
|
|
13
|
+
exports.PLATFORM_MODULES = ['react', 'react-dom', 'recharts', '@tanstack/react-table', 'sa', '@solidactions/sa'];
|
|
14
|
+
exports.COMPILED_LIMIT_BYTES = 2 * 1024 * 1024;
|
|
15
|
+
exports.SOURCES_MAX_FILES = 50;
|
|
16
|
+
exports.SOURCES_MAX_BYTES = 1024 * 1024;
|
|
17
|
+
class PageBundleError extends Error {
|
|
18
|
+
}
|
|
19
|
+
exports.PageBundleError = PageBundleError;
|
|
20
|
+
const MAIN = 'sa-page:main';
|
|
21
|
+
const PLATFORM_NAMESPACE = 'sa-platform';
|
|
22
|
+
const WRAP_PREFIX = 'globalThis.__saPlatform.define(function () {\n';
|
|
23
|
+
const WRAP_SUFFIX = '});\n';
|
|
24
|
+
const NO_DEFAULT_EXPORT = 'a page must export its component as the default export';
|
|
25
|
+
const COMPUTED_SPECIFIER = 'import() and require() of a computed specifier are not allowed in a page; import platform modules by name: react, react-dom, recharts, @tanstack/react-table, sa';
|
|
26
|
+
const PLATFORM_LIST = 'react, react-dom, recharts, @tanstack/react-table, sa, @solidactions/sa';
|
|
27
|
+
function platformPlugin() {
|
|
28
|
+
return {
|
|
29
|
+
name: 'sa-platform',
|
|
30
|
+
setup(b) {
|
|
31
|
+
b.onResolve({ filter: /^[^./]/ }, (args) => {
|
|
32
|
+
if (exports.PLATFORM_MODULES.includes(args.path)) {
|
|
33
|
+
return { path: args.path, namespace: PLATFORM_NAMESPACE };
|
|
34
|
+
}
|
|
35
|
+
if (exports.PLATFORM_MODULES.some(name => args.path.startsWith(`${name}/`))) {
|
|
36
|
+
return { errors: [{ text: `import "${args.path}" is not available: platform modules are imported by name only (${PLATFORM_LIST})` }] };
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
});
|
|
40
|
+
b.onLoad({ filter: /.*/, namespace: PLATFORM_NAMESPACE }, (args) => ({
|
|
41
|
+
contents: `module.exports = globalThis.__saPlatform.modules[${JSON.stringify(args.path)}];\n`,
|
|
42
|
+
loader: 'js',
|
|
43
|
+
}));
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function toPosix(value) {
|
|
48
|
+
return value.split(path_1.default.sep).join('/').replace(/\\/g, '/');
|
|
49
|
+
}
|
|
50
|
+
function loaderForExtension(ext) {
|
|
51
|
+
switch (ext) {
|
|
52
|
+
case '.ts':
|
|
53
|
+
case '.mts':
|
|
54
|
+
case '.cts':
|
|
55
|
+
return 'ts';
|
|
56
|
+
case '.tsx':
|
|
57
|
+
return 'tsx';
|
|
58
|
+
case '.js':
|
|
59
|
+
case '.mjs':
|
|
60
|
+
case '.cjs':
|
|
61
|
+
return 'js';
|
|
62
|
+
case '.jsx':
|
|
63
|
+
return 'jsx';
|
|
64
|
+
case '.json':
|
|
65
|
+
return 'json';
|
|
66
|
+
case '.css':
|
|
67
|
+
return 'css';
|
|
68
|
+
case '.txt':
|
|
69
|
+
return 'text';
|
|
70
|
+
default:
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// True when a project-relative path escapes the project root. A leading
|
|
75
|
+
// `..` path component means outside; a mere `..` prefix does not (files
|
|
76
|
+
// like `lib/..shared.ts` or dirs like `..lib/` are valid project paths).
|
|
77
|
+
// Check both separators: metafile keys are posix, but path.relative
|
|
78
|
+
// speaks the OS separator — and on Windows it returns an absolute drive
|
|
79
|
+
// path when the target is on another drive, which no prefix check sees.
|
|
80
|
+
function isOutsideRoot(relative) {
|
|
81
|
+
const posix = toPosix(relative);
|
|
82
|
+
return path_1.default.isAbsolute(relative) || posix === '..' || posix.startsWith('../') || relative === '..' || relative.startsWith(`..${path_1.default.sep}`);
|
|
83
|
+
}
|
|
84
|
+
function describe(message, projectDir) {
|
|
85
|
+
// esbuild keeps the returning plugin's name on a plugin error
|
|
86
|
+
// (probed on 0.28.2: pluginName "sa-capture"/"sa-platform", id "").
|
|
87
|
+
// A plugin error is classified by what it IS — its own text — never
|
|
88
|
+
// by where it is reported: the entry's outside-root refusal is
|
|
89
|
+
// reported from the virtual sa-page:main import, where a
|
|
90
|
+
// location-based rule misreads it as a missing default export.
|
|
91
|
+
const pluginError = message.pluginName === 'sa-platform' || message.pluginName === 'sa-capture';
|
|
92
|
+
const reportedFromMain = message.location?.file === MAIN || message.location?.file === '<stdin>';
|
|
93
|
+
if (pluginError && reportedFromMain)
|
|
94
|
+
return message.text;
|
|
95
|
+
const fromMain = reportedFromMain;
|
|
96
|
+
const computed = message.id === 'unsupported-dynamic-import' || message.id === 'unsupported-require-call';
|
|
97
|
+
const text = fromMain ? NO_DEFAULT_EXPORT : computed ? COMPUTED_SPECIFIER : message.text;
|
|
98
|
+
if (fromMain || !message.location?.file)
|
|
99
|
+
return text;
|
|
100
|
+
const file = toPosix(path_1.default.relative(projectDir, path_1.default.resolve(projectDir, message.location.file)));
|
|
101
|
+
return `${file}:${message.location.line}:${message.location.column}: ${text}`;
|
|
102
|
+
}
|
|
103
|
+
// Source assembly is a pure function of the bytes captured during the
|
|
104
|
+
// build and the build's metafile: it walks the captured map (keyed by the
|
|
105
|
+
// exact path esbuild passed to onLoad) and the metafile decides which of
|
|
106
|
+
// those paths were part of the build. Nothing here may consult the live
|
|
107
|
+
// tree, so a file replaced after compilation cannot change the published
|
|
108
|
+
// snapshot. The sweep row `keeps source assembly free of filesystem
|
|
109
|
+
// calls` pins that shape at the source level.
|
|
110
|
+
function assembleSources(captured, metafile, realRoot, entryKey) {
|
|
111
|
+
if (metafile.inputs[entryKey]?.format !== 'esm')
|
|
112
|
+
throw new PageBundleError(NO_DEFAULT_EXPORT);
|
|
113
|
+
const builtKeys = new Set(Object.keys(metafile.inputs).map(toPosix));
|
|
114
|
+
const sources = {};
|
|
115
|
+
let totalBytes = 0;
|
|
116
|
+
for (const [absPath, text] of captured) {
|
|
117
|
+
const key = toPosix(path_1.default.relative(realRoot, absPath));
|
|
118
|
+
if (key.split('/').includes('node_modules'))
|
|
119
|
+
continue;
|
|
120
|
+
if (!builtKeys.has(key))
|
|
121
|
+
continue;
|
|
122
|
+
sources[key] = text;
|
|
123
|
+
totalBytes += Buffer.byteLength(text);
|
|
124
|
+
}
|
|
125
|
+
for (const key of Object.keys(metafile.inputs)) {
|
|
126
|
+
if (key.startsWith(`${PLATFORM_NAMESPACE}:`) || key === MAIN || key === '<stdin>')
|
|
127
|
+
continue;
|
|
128
|
+
const posix = toPosix(key);
|
|
129
|
+
// An absolute key is never skipped as node_modules: outside-root
|
|
130
|
+
// is the outside refusal, inside-root is an unexpected-path refusal.
|
|
131
|
+
if (path_1.default.isAbsolute(key) || /^[A-Za-z]:[\\/]/.test(key) || posix.startsWith('/')) {
|
|
132
|
+
if (isOutsideRoot(path_1.default.relative(realRoot, key))) {
|
|
133
|
+
throw new PageBundleError(`${posix}: imported from outside the project directory; a page can only import files inside its project`);
|
|
134
|
+
}
|
|
135
|
+
throw new PageBundleError(`${posix}: unexpected absolute input path`);
|
|
136
|
+
}
|
|
137
|
+
// Containment first: a `..`-prefixed key is never skipped as
|
|
138
|
+
// node_modules, it is a refusal.
|
|
139
|
+
if (isOutsideRoot(path_1.default.relative(realRoot, path_1.default.resolve(realRoot, key)))) {
|
|
140
|
+
throw new PageBundleError(`${toPosix(key)}: imported from outside the project directory; a page can only import files inside its project`);
|
|
141
|
+
}
|
|
142
|
+
if (posix.split('/').includes('node_modules'))
|
|
143
|
+
continue;
|
|
144
|
+
if (!(posix in sources))
|
|
145
|
+
throw new PageBundleError(`${posix}: unsupported file type for a page`);
|
|
146
|
+
}
|
|
147
|
+
if (Object.keys(sources).length > exports.SOURCES_MAX_FILES)
|
|
148
|
+
throw new PageBundleError(`the page reads ${Object.keys(sources).length} project files, over the ${exports.SOURCES_MAX_FILES} file limit`);
|
|
149
|
+
if (totalBytes > exports.SOURCES_MAX_BYTES)
|
|
150
|
+
throw new PageBundleError(`the page's project files total ${totalBytes} bytes, over the 1 MiB (${exports.SOURCES_MAX_BYTES} bytes) limit`);
|
|
151
|
+
const entrySource = sources[entryKey];
|
|
152
|
+
if (entrySource === undefined)
|
|
153
|
+
throw new PageBundleError(`${entryKey}: unsupported file type for a page`);
|
|
154
|
+
return { sources, entrySource };
|
|
155
|
+
}
|
|
156
|
+
// ONE reader serves every file esbuild loads, project files and in-root
|
|
157
|
+
// node_modules alike: onLoad always returns contents for a file-namespace
|
|
158
|
+
// path, never null, so esbuild never reads a file from disk itself. The
|
|
159
|
+
// returned bytes are read from the open handle whose post-open
|
|
160
|
+
// verification matches the admitted file; anything else is a refusal
|
|
161
|
+
// naming the path. Nothing is re-read.
|
|
162
|
+
function readAdmitted(requestedPath, realRoot, hooks) {
|
|
163
|
+
const requestedDisplay = toPosix(path_1.default.relative(realRoot, requestedPath));
|
|
164
|
+
let real;
|
|
165
|
+
try {
|
|
166
|
+
real = fs_1.default.realpathSync(requestedPath);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
throw new PageBundleError(`${requestedDisplay}: could not resolve the real path`);
|
|
170
|
+
}
|
|
171
|
+
const display = toPosix(path_1.default.relative(realRoot, real));
|
|
172
|
+
if (isOutsideRoot(path_1.default.relative(realRoot, real))) {
|
|
173
|
+
throw new PageBundleError(`${display}: imported from outside the project directory; a page can only import files inside its project`);
|
|
174
|
+
}
|
|
175
|
+
// TEST SEAM beforeStat: strictly between the containment check and
|
|
176
|
+
// the pre-open stat.
|
|
177
|
+
hooks?.beforeStat?.(real);
|
|
178
|
+
// The pre-open stat records the admitted identity AND the regular-file
|
|
179
|
+
// gate. A swap of the admitted file for another IN-ROOT regular file
|
|
180
|
+
// here is not detectable and is harmless to the outside-root rule: the
|
|
181
|
+
// read bytes still come from a file inside the root and are the bytes
|
|
182
|
+
// captured.
|
|
183
|
+
let before;
|
|
184
|
+
try {
|
|
185
|
+
before = fs_1.default.statSync(real);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
189
|
+
}
|
|
190
|
+
if (!before.isFile()) {
|
|
191
|
+
throw new PageBundleError(`${display}: not a regular file`);
|
|
192
|
+
}
|
|
193
|
+
// TEST SEAM beforeOpen: after the pre-open stat, before the open.
|
|
194
|
+
hooks?.beforeOpen?.(real);
|
|
195
|
+
let fd;
|
|
196
|
+
try {
|
|
197
|
+
fd = fs_1.default.openSync(real, fs_1.default.constants.O_RDONLY | (fs_1.default.constants.O_NOFOLLOW ?? 0));
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
const after = fs_1.default.fstatSync(fd);
|
|
204
|
+
if (!after.isFile()) {
|
|
205
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
206
|
+
}
|
|
207
|
+
// Where the OPEN HANDLE really lives, asked from the kernel: an
|
|
208
|
+
// intermediate directory swapped for an outside symlink between
|
|
209
|
+
// the admission realpath and the open lands here, while
|
|
210
|
+
// O_NOFOLLOW only guards the final component.
|
|
211
|
+
let fdReal = null;
|
|
212
|
+
try {
|
|
213
|
+
fdReal = fs_1.default.realpathSync(`/proc/self/fd/${fd}`);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
const code = error.code;
|
|
217
|
+
const failedPath = String(error.path ?? '');
|
|
218
|
+
if (failedPath.endsWith(' (deleted)')) {
|
|
219
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
220
|
+
}
|
|
221
|
+
// No /proc on this platform (macOS, Windows, restricted
|
|
222
|
+
// containers): skip the kernel check and rely on the fallback
|
|
223
|
+
// layer below. Node has no openat/F_GETPATH; where /proc is
|
|
224
|
+
// unavailable a directory swapped twice in a few microseconds
|
|
225
|
+
// is the documented residual; the resolver's own path stats
|
|
226
|
+
// only choose paths, never bytes. Never skip silently on
|
|
227
|
+
// Linux: any other readlink failure refuses.
|
|
228
|
+
if (process.platform === 'linux' && code !== 'ENOENT' && code !== 'ENOTDIR') {
|
|
229
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
230
|
+
}
|
|
231
|
+
fdReal = null;
|
|
232
|
+
}
|
|
233
|
+
if (fdReal !== null && isOutsideRoot(path_1.default.relative(realRoot, fdReal))) {
|
|
234
|
+
throw new PageBundleError(`${display}: imported from outside the project directory; a page can only import files inside its project`);
|
|
235
|
+
}
|
|
236
|
+
// The open handle must still match the pre-open identity: this
|
|
237
|
+
// catches a swap in the beforeOpen window above.
|
|
238
|
+
if (after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size) {
|
|
239
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
240
|
+
}
|
|
241
|
+
// TEST SEAM afterOpen: after the open, before the post-open
|
|
242
|
+
// verification below.
|
|
243
|
+
hooks?.afterOpen?.(real);
|
|
244
|
+
// The comparison stat is taken AFTER the open: it must describe
|
|
245
|
+
// the same file the handle does. Best-effort fallback layer for
|
|
246
|
+
// platforms without /proc: the path must still resolve to the
|
|
247
|
+
// admitted file.
|
|
248
|
+
let post;
|
|
249
|
+
try {
|
|
250
|
+
post = fs_1.default.statSync(real);
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
254
|
+
}
|
|
255
|
+
// dev+ino is the identity; size is compared too because ino is 0
|
|
256
|
+
// or otherwise unreliable on some platforms. Windows is
|
|
257
|
+
// best-effort: the predicates above are source-level there and the
|
|
258
|
+
// suite skips symlink rows on win32.
|
|
259
|
+
if (!post.isFile() || after.dev !== post.dev || after.ino !== post.ino || after.size !== post.size) {
|
|
260
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
261
|
+
}
|
|
262
|
+
let reread;
|
|
263
|
+
try {
|
|
264
|
+
reread = fs_1.default.realpathSync(real);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
268
|
+
}
|
|
269
|
+
if (reread !== real) {
|
|
270
|
+
throw new PageBundleError(`${display}: changed while it was being read; deploy again`);
|
|
271
|
+
}
|
|
272
|
+
return fs_1.default.readFileSync(fd, 'utf8');
|
|
273
|
+
}
|
|
274
|
+
finally {
|
|
275
|
+
fs_1.default.closeSync(fd);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async function bundlePage(entryPath, projectDir, hooks) {
|
|
279
|
+
// test seam: the window between compilation and result assembly
|
|
280
|
+
const root = path_1.default.resolve(projectDir);
|
|
281
|
+
const entry = path_1.default.resolve(root, entryPath);
|
|
282
|
+
// The root and entry are resolved ONCE before the build: realRoot is
|
|
283
|
+
// the compilation directory and realEntry feeds the entry key. No
|
|
284
|
+
// project path is resolved again after the build starts. A missing
|
|
285
|
+
// entry keeps the lexical path so the refusal below reports it exactly
|
|
286
|
+
// as before.
|
|
287
|
+
const realRoot = fs_1.default.realpathSync(root);
|
|
288
|
+
const realEntry = fs_1.default.existsSync(entry) ? fs_1.default.realpathSync(entry) : entry;
|
|
289
|
+
const entryKey = toPosix(path_1.default.relative(realRoot, realEntry));
|
|
290
|
+
// Keyed by the exact path esbuild passes to onLoad: the association
|
|
291
|
+
// between a compiled input and its bytes is fixed at capture time and
|
|
292
|
+
// never re-resolved from the live tree.
|
|
293
|
+
const captured = new Map();
|
|
294
|
+
const capturePlugin = {
|
|
295
|
+
name: 'sa-capture',
|
|
296
|
+
setup(b) {
|
|
297
|
+
b.onLoad({ filter: /.*/, namespace: 'file' }, (args) => {
|
|
298
|
+
// Every file-namespace path — project files, in-root
|
|
299
|
+
// node_modules files, any unmapped extension — is read
|
|
300
|
+
// through the single admitted reader, and this handler
|
|
301
|
+
// always returns its contents: it never returns null, so
|
|
302
|
+
// esbuild never reads a file from disk itself. A real path
|
|
303
|
+
// outside the root is refused naming its path (this
|
|
304
|
+
// deliberately refuses hoisted/workspace packages resolving
|
|
305
|
+
// above the project root), and its bytes never reach esbuild.
|
|
306
|
+
// The plugin's contents come ONLY from this one admitted-reader
|
|
307
|
+
// call: there is no other byte source in this handler, so
|
|
308
|
+
// esbuild never reads a file from disk itself.
|
|
309
|
+
let contents;
|
|
310
|
+
try {
|
|
311
|
+
contents = readAdmitted(args.path, realRoot, hooks);
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
if (error instanceof PageBundleError)
|
|
315
|
+
return { errors: [{ text: error.message }] };
|
|
316
|
+
throw error;
|
|
317
|
+
}
|
|
318
|
+
// esbuild defaults *.module.css to the local-css loader (scoped
|
|
319
|
+
// class names); return the same loader so capture is behavior-preserving.
|
|
320
|
+
const loader = args.path.endsWith('.module.css')
|
|
321
|
+
? 'local-css'
|
|
322
|
+
: loaderForExtension(path_1.default.extname(args.path));
|
|
323
|
+
if (loader === null) {
|
|
324
|
+
return { errors: [{ text: `${toPosix(path_1.default.relative(realRoot, args.path))}: unsupported file type for a page` }] };
|
|
325
|
+
}
|
|
326
|
+
// Bytes the reader returns for a project file are recorded
|
|
327
|
+
// in the captured map exactly as before (keyed by the path
|
|
328
|
+
// esbuild passes) and are the bytes esbuild compiles;
|
|
329
|
+
// node_modules bytes are consumed once and not recorded.
|
|
330
|
+
if (!toPosix(args.path).split('/').includes('node_modules')) {
|
|
331
|
+
captured.set(args.path, contents);
|
|
332
|
+
}
|
|
333
|
+
hooks?.onLoaded?.(args.path, contents);
|
|
334
|
+
return { contents, loader };
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
let result;
|
|
339
|
+
try {
|
|
340
|
+
result = await (0, esbuild_1.build)({
|
|
341
|
+
stdin: {
|
|
342
|
+
contents: `import Page from ${JSON.stringify(entry)};\nglobalThis.__saPlatform.mount(Page);\n`,
|
|
343
|
+
resolveDir: root,
|
|
344
|
+
sourcefile: MAIN,
|
|
345
|
+
loader: 'js',
|
|
346
|
+
},
|
|
347
|
+
absWorkingDir: realRoot,
|
|
348
|
+
outdir: path_1.default.join(root, '.sa-page-out'),
|
|
349
|
+
bundle: true,
|
|
350
|
+
write: false,
|
|
351
|
+
metafile: true,
|
|
352
|
+
logLevel: 'silent',
|
|
353
|
+
format: 'iife',
|
|
354
|
+
target: 'es2022',
|
|
355
|
+
platform: 'browser',
|
|
356
|
+
charset: 'utf8',
|
|
357
|
+
legalComments: 'none',
|
|
358
|
+
minify: false,
|
|
359
|
+
jsx: 'transform',
|
|
360
|
+
jsxFactory: 'React.createElement',
|
|
361
|
+
jsxFragment: 'React.Fragment',
|
|
362
|
+
logOverride: { 'unsupported-dynamic-import': 'error', 'unsupported-require-call': 'error' },
|
|
363
|
+
tsconfigRaw: { compilerOptions: { verbatimModuleSyntax: true } },
|
|
364
|
+
plugins: [platformPlugin(), capturePlugin],
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
if (error instanceof PageBundleError)
|
|
369
|
+
throw error;
|
|
370
|
+
const errors = error.errors;
|
|
371
|
+
if (!Array.isArray(errors) || errors.length === 0)
|
|
372
|
+
throw new PageBundleError(String(error.message ?? 'bundle failed'));
|
|
373
|
+
throw new PageBundleError([...new Set(errors.slice(0, 20).map(message => describe(message, root)))].join('\n'));
|
|
374
|
+
}
|
|
375
|
+
hooks?.onMetafile?.(result.metafile);
|
|
376
|
+
await hooks?.afterBundle?.();
|
|
377
|
+
// The resolved entry is checked against the project root before
|
|
378
|
+
// assembly: an entry symlink pointing outside (even to a CommonJS
|
|
379
|
+
// file, even across Windows drives) is an outside-the-project refusal,
|
|
380
|
+
// not a missing default export. A missing entry keeps its lexical
|
|
381
|
+
// in-project key and still reports the no-default-export message from
|
|
382
|
+
// assembly below.
|
|
383
|
+
if (isOutsideRoot(path_1.default.relative(realRoot, realEntry))) {
|
|
384
|
+
throw new PageBundleError(`${entryKey}: imported from outside the project directory; a page can only import files inside its project`);
|
|
385
|
+
}
|
|
386
|
+
// entrySource, sources and compiled all come from the same pre-build
|
|
387
|
+
// capture: assembly reads only the captured map and the metafile.
|
|
388
|
+
const { sources, entrySource } = assembleSources(captured, result.metafile, realRoot, entryKey);
|
|
389
|
+
const js = result.outputFiles.find(file => file.path.endsWith('.js'))?.text ?? '';
|
|
390
|
+
const css = result.outputFiles.find(file => file.path.endsWith('.css'))?.text ?? '';
|
|
391
|
+
const compiled = `${WRAP_PREFIX}${js}${WRAP_SUFFIX}`;
|
|
392
|
+
if (/<\/script/i.test(compiled))
|
|
393
|
+
throw new PageBundleError('the compiled page contains "</script", which would end the script tag it is served in; split the string (for example "<\\/script")');
|
|
394
|
+
const size = Buffer.byteLength(compiled);
|
|
395
|
+
if (size > exports.COMPILED_LIMIT_BYTES)
|
|
396
|
+
throw new PageBundleError(`the compiled page is ${size} bytes, over the 2 MiB (${exports.COMPILED_LIMIT_BYTES} bytes) limit`);
|
|
397
|
+
return { compiled, compiledCss: css, sources, compilerVersion: esbuild_1.version, entrySource };
|
|
398
|
+
}
|
package/dist/utils/pages-sync.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.listCodePages = listCodePages;
|
|
7
7
|
exports.readPageBodies = readPageBodies;
|
|
8
|
+
exports.bundleCodePages = bundleCodePages;
|
|
8
9
|
exports.buildPagesSyncPayload = buildPagesSyncPayload;
|
|
9
10
|
exports.formatPagesSummary = formatPagesSummary;
|
|
10
11
|
exports.pagesSyncOutcome = pagesSyncOutcome;
|
|
@@ -16,12 +17,14 @@ const path_1 = __importDefault(require("path"));
|
|
|
16
17
|
const axios_1 = __importDefault(require("axios"));
|
|
17
18
|
const api_1 = require("./api");
|
|
18
19
|
const validate_items_1 = require("./validate-items");
|
|
20
|
+
const page_bundle_1 = require("./page-bundle");
|
|
19
21
|
function listCodePages(config) {
|
|
20
22
|
return (config.pages ?? []).filter(page => !(0, validate_items_1.isPagePointer)(page)).map(page => ({
|
|
21
23
|
slug: page.id,
|
|
22
24
|
name: page.name,
|
|
23
25
|
path: page.file,
|
|
24
26
|
kind: page.file.endsWith('.html') ? 'visual' : 'dashboard',
|
|
27
|
+
language: page.file.endsWith('.tsx') ? 'tsx' : 'html',
|
|
25
28
|
home: page.home ?? false,
|
|
26
29
|
...(page.sources === undefined ? {} : { sources: page.sources }),
|
|
27
30
|
}));
|
|
@@ -29,8 +32,31 @@ function listCodePages(config) {
|
|
|
29
32
|
function readPageBodies(sourceDir, pages) {
|
|
30
33
|
return new Map(pages.map(page => [page.slug, fs_1.default.readFileSync(path_1.default.join(sourceDir, page.path), 'utf8')]));
|
|
31
34
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
35
|
+
async function bundleCodePages(sourceDir, pages) {
|
|
36
|
+
const bundles = new Map();
|
|
37
|
+
const errors = [];
|
|
38
|
+
for (const page of pages.filter(candidate => candidate.language === 'tsx')) {
|
|
39
|
+
try {
|
|
40
|
+
bundles.set(page.slug, await (0, page_bundle_1.bundlePage)(path_1.default.join(sourceDir, page.path), sourceDir));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
const lines = String(error?.message ?? 'bundle failed').split('\n');
|
|
44
|
+
errors.push(`page ${page.slug} (${page.path}): ${lines[0]}`, ...lines.slice(1).map(line => ` ${line}`));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { bundles, errors };
|
|
48
|
+
}
|
|
49
|
+
function buildPagesSyncPayload(pages, bodies, deploymentId, codeRef, bundles) {
|
|
50
|
+
return {
|
|
51
|
+
deployment_id: deploymentId,
|
|
52
|
+
code_ref: codeRef,
|
|
53
|
+
pages: pages.map(page => {
|
|
54
|
+
const bundle = bundles?.get(page.slug);
|
|
55
|
+
if (bundle === undefined)
|
|
56
|
+
return { ...page, body: bodies.get(page.slug) };
|
|
57
|
+
return { ...page, body: bundle.entrySource, source_files: bundle.sources, compiled: bundle.compiled, compiled_css: bundle.compiledCss, compiler_version: bundle.compilerVersion };
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
34
60
|
}
|
|
35
61
|
function formatPagesSummary(rows, trashed, trashErrors) {
|
|
36
62
|
return [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidactions/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.33.0",
|
|
4
4
|
"description": "SolidActions CLI - Deploy and manage workflow automation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"chalk": "^4.1.2",
|
|
47
47
|
"commander": "^11.0.0",
|
|
48
48
|
"dotenv": "^17.3.1",
|
|
49
|
+
"esbuild": "0.28.2",
|
|
49
50
|
"form-data": "^4.0.6",
|
|
50
51
|
"fs-extra": "^11.0.0",
|
|
51
52
|
"ignore": "^7.0.5",
|