@nova-energy/openamx 0.19.0 → 0.21.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/README.md +7 -2
- package/dist/cli.js +61 -0
- package/dist/index.js +1 -0
- package/dist/renderer/diagramBrowserRuntime.js +1 -1
- package/dist/runtime/evaluateExpression.js +105 -0
- package/dist/runtime/inputData.js +73 -20
- package/dist/runtime/moduleLoader.js +6 -3
- package/dist/transpiler/emit.js +842 -0
- package/dist/transpiler/filesystemGraph.js +267 -0
- package/dist/transpiler/graph.js +200 -0
- package/dist/transpiler/index.js +52 -0
- package/dist/transpiler/outputWriter.js +378 -0
- package/dist/transpiler/source.js +16 -0
- package/dist/transpiler/types.js +1 -0
- package/dist/transpilerRuntime.js +684 -0
- package/dist/typechecker/checkDocument.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { AmxError } from '../diagnostics/errors';
|
|
5
|
+
export class TranspileOutputError extends AmxError {
|
|
6
|
+
pathStates;
|
|
7
|
+
retainedStagePath;
|
|
8
|
+
constructor(code, message, pathStates = [], retainedStagePath) {
|
|
9
|
+
super({ code, message });
|
|
10
|
+
this.pathStates = pathStates;
|
|
11
|
+
this.retainedStagePath = retainedStagePath;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function outputError(code, message) {
|
|
15
|
+
throw new TranspileOutputError(code, message);
|
|
16
|
+
}
|
|
17
|
+
function lstatIfExists(target) {
|
|
18
|
+
try {
|
|
19
|
+
return lstatSync(target);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error.code === 'ENOENT')
|
|
23
|
+
return undefined;
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function isWithinDirectory(root, candidate) {
|
|
28
|
+
const relativePath = path.relative(root, candidate);
|
|
29
|
+
return relativePath !== '' && relativePath !== '..'
|
|
30
|
+
&& !relativePath.startsWith(`..${path.sep}`) && !path.isAbsolute(relativePath);
|
|
31
|
+
}
|
|
32
|
+
function canonicalizeFuturePath(target) {
|
|
33
|
+
let cursor = path.resolve(target);
|
|
34
|
+
const suffix = [];
|
|
35
|
+
while (!lstatIfExists(cursor)) {
|
|
36
|
+
const parent = path.dirname(cursor);
|
|
37
|
+
if (parent === cursor)
|
|
38
|
+
throw new Error(`No existing parent for '${target}'`);
|
|
39
|
+
suffix.unshift(path.basename(cursor));
|
|
40
|
+
cursor = parent;
|
|
41
|
+
}
|
|
42
|
+
if (suffix.length && !statSync(cursor).isDirectory()) {
|
|
43
|
+
outputError('AMX6001', `Output path has a non-directory parent '${cursor}'`);
|
|
44
|
+
}
|
|
45
|
+
return path.resolve(realpathSync(cursor), ...suffix);
|
|
46
|
+
}
|
|
47
|
+
function missingDirectories(target) {
|
|
48
|
+
let cursor = path.resolve(target);
|
|
49
|
+
const missing = [];
|
|
50
|
+
while (!lstatIfExists(cursor)) {
|
|
51
|
+
missing.push(cursor);
|
|
52
|
+
const parent = path.dirname(cursor);
|
|
53
|
+
if (parent === cursor)
|
|
54
|
+
break;
|
|
55
|
+
cursor = parent;
|
|
56
|
+
}
|
|
57
|
+
return missing.reverse();
|
|
58
|
+
}
|
|
59
|
+
function ensureRelativeOutputPath(outputPath) {
|
|
60
|
+
const segments = outputPath.split('/');
|
|
61
|
+
if (!outputPath || outputPath.includes('\\') || path.posix.isAbsolute(outputPath)
|
|
62
|
+
|| segments.some(segment => !segment || segment === '.' || segment === '..')
|
|
63
|
+
|| path.posix.normalize(outputPath) !== outputPath || !outputPath.endsWith('.ts')) {
|
|
64
|
+
outputError('AMX6001', `Invalid output-relative TypeScript path '${outputPath}'`);
|
|
65
|
+
}
|
|
66
|
+
return segments;
|
|
67
|
+
}
|
|
68
|
+
function normalizedKey(value) {
|
|
69
|
+
return value.normalize('NFC').replaceAll('\\', '/').toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
function sourceRootForEntry(entry) {
|
|
72
|
+
const outputDirectory = path.posix.dirname(entry.outputPath);
|
|
73
|
+
const depth = outputDirectory === '.' ? 0 : outputDirectory.split('/').length;
|
|
74
|
+
let root = path.dirname(entry.sourcePath);
|
|
75
|
+
for (let index = 0; index < depth; index++)
|
|
76
|
+
root = path.dirname(root);
|
|
77
|
+
return realpathSync(root);
|
|
78
|
+
}
|
|
79
|
+
function preflight(modules, entryModuleId, outputDirectory, overwrite) {
|
|
80
|
+
if (!outputDirectory.trim())
|
|
81
|
+
outputError('AMX6001', 'An explicit output directory is required');
|
|
82
|
+
const entry = modules.find(module => module.moduleId === entryModuleId);
|
|
83
|
+
if (!entry)
|
|
84
|
+
outputError('AMX6001', 'The generated graph does not contain its entry module');
|
|
85
|
+
const segmentsByModule = new Map(modules.map(module => [module.moduleId, ensureRelativeOutputPath(module.outputPath)]));
|
|
86
|
+
const root = canonicalizeFuturePath(outputDirectory);
|
|
87
|
+
const rootStat = lstatIfExists(root);
|
|
88
|
+
if (rootStat && !statSync(root).isDirectory())
|
|
89
|
+
outputError('AMX6001', 'Output root must be a directory');
|
|
90
|
+
const sourceRoot = sourceRootForEntry(entry);
|
|
91
|
+
if (root === sourceRoot || isWithinDirectory(sourceRoot, root)) {
|
|
92
|
+
outputError('AMX6001', 'Output directory must not be inside the AMX import root');
|
|
93
|
+
}
|
|
94
|
+
const sourceKeys = new Set(modules.map(module => normalizedKey(realpathSync(module.sourcePath))));
|
|
95
|
+
const outputKeys = new Set();
|
|
96
|
+
const targetKeys = new Set();
|
|
97
|
+
const targets = [];
|
|
98
|
+
const conflicts = [];
|
|
99
|
+
for (const module of modules) {
|
|
100
|
+
const segments = segmentsByModule.get(module.moduleId);
|
|
101
|
+
const outputKey = normalizedKey(module.outputPath);
|
|
102
|
+
if (outputKeys.has(outputKey))
|
|
103
|
+
outputError('AMX6001', `Output path collision at '${module.outputPath}'`);
|
|
104
|
+
outputKeys.add(outputKey);
|
|
105
|
+
const absolutePath = path.resolve(root, ...segments);
|
|
106
|
+
const canonicalTarget = canonicalizeFuturePath(absolutePath);
|
|
107
|
+
if (!isWithinDirectory(root, canonicalTarget)) {
|
|
108
|
+
outputError('AMX6001', `Output target escapes the selected directory: '${module.outputPath}'`);
|
|
109
|
+
}
|
|
110
|
+
if (sourceKeys.has(normalizedKey(canonicalTarget))) {
|
|
111
|
+
outputError('AMX6001', `Output target aliases an AMX source: '${module.outputPath}'`);
|
|
112
|
+
}
|
|
113
|
+
const targetKey = normalizedKey(canonicalTarget);
|
|
114
|
+
if (targetKeys.has(targetKey))
|
|
115
|
+
outputError('AMX6001', `Output targets alias at '${module.outputPath}'`);
|
|
116
|
+
targetKeys.add(targetKey);
|
|
117
|
+
let parent = root;
|
|
118
|
+
for (const segment of segments.slice(0, -1)) {
|
|
119
|
+
parent = path.join(parent, segment);
|
|
120
|
+
if (lstatIfExists(parent) && !statSync(parent).isDirectory()) {
|
|
121
|
+
outputError('AMX6001', `Output parent is not a directory: '${module.outputPath}'`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const targetStat = lstatIfExists(absolutePath);
|
|
125
|
+
if (targetStat?.isSymbolicLink()) {
|
|
126
|
+
outputError('AMX6001', `Refusing symbolic-link output target '${module.outputPath}'`);
|
|
127
|
+
}
|
|
128
|
+
if (targetStat && !targetStat.isFile()) {
|
|
129
|
+
outputError('AMX6001', `Output target is not a regular file: '${module.outputPath}'`);
|
|
130
|
+
}
|
|
131
|
+
if (targetStat && !overwrite)
|
|
132
|
+
conflicts.push(module.outputPath);
|
|
133
|
+
const original = targetStat ? {
|
|
134
|
+
sha256: sha256(readFileSync(absolutePath)),
|
|
135
|
+
size: Number(targetStat.size),
|
|
136
|
+
mode: Number(targetStat.mode),
|
|
137
|
+
modifiedAt: Number(targetStat.mtimeMs)
|
|
138
|
+
} : undefined;
|
|
139
|
+
targets.push({ module, absolutePath, exists: Boolean(targetStat), original });
|
|
140
|
+
}
|
|
141
|
+
const sortedKeys = [...outputKeys].sort();
|
|
142
|
+
for (let index = 0; index < sortedKeys.length; index++) {
|
|
143
|
+
const current = sortedKeys[index];
|
|
144
|
+
if (sortedKeys.slice(index + 1).some(other => other.startsWith(`${current}/`))) {
|
|
145
|
+
outputError('AMX6001', `Output file/directory conflict at '${current}'`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (conflicts.length) {
|
|
149
|
+
outputError('AMX6001', `Existing output targets require --overwrite: ${conflicts.sort().join(', ')}`);
|
|
150
|
+
}
|
|
151
|
+
const rootMetadata = rootStat ? statSync(root) : undefined;
|
|
152
|
+
return {
|
|
153
|
+
root,
|
|
154
|
+
...(rootMetadata ? { rootIdentity: { device: Number(rootMetadata.dev), inode: Number(rootMetadata.ino) } } : {}),
|
|
155
|
+
targets
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function sha256(bytes) {
|
|
159
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
160
|
+
}
|
|
161
|
+
function graphHash(result) {
|
|
162
|
+
const graph = {
|
|
163
|
+
entryModuleId: result.entryModuleId,
|
|
164
|
+
modules: result.modules.map(({ moduleId, sourcePath, outputPath, code }) => ({ moduleId, sourcePath, outputPath, code }))
|
|
165
|
+
};
|
|
166
|
+
return createHash('sha256').update(JSON.stringify(graph), 'utf8').digest('hex');
|
|
167
|
+
}
|
|
168
|
+
function sameTargetPlan(expected, actual) {
|
|
169
|
+
return expected.outputPath === actual.module.outputPath
|
|
170
|
+
&& expected.exists === actual.exists
|
|
171
|
+
&& expected.sha256 === actual.original?.sha256
|
|
172
|
+
&& expected.size === actual.original?.size
|
|
173
|
+
&& expected.mode === actual.original?.mode
|
|
174
|
+
&& expected.modifiedAt === actual.original?.modifiedAt;
|
|
175
|
+
}
|
|
176
|
+
function assertExpectedPlan(result, expected, actual) {
|
|
177
|
+
if (expected.entryModuleId !== result.entryModuleId || expected.graphHash !== graphHash(result)
|
|
178
|
+
|| expected.outputDirectory !== actual.root
|
|
179
|
+
|| !actual.rootIdentity
|
|
180
|
+
|| expected.rootIdentity.device !== actual.rootIdentity.device
|
|
181
|
+
|| expected.rootIdentity.inode !== actual.rootIdentity.inode
|
|
182
|
+
|| expected.targets.length !== actual.targets.length
|
|
183
|
+
|| expected.targets.some((target, index) => !sameTargetPlan(target, actual.targets[index]))) {
|
|
184
|
+
outputError('AMX6001', 'Graph output changed after overwrite approval; no output was written');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export function inspectTranspiledGraphWrite(result, outputDirectory) {
|
|
188
|
+
let plan;
|
|
189
|
+
try {
|
|
190
|
+
plan = preflight(result.modules, result.entryModuleId, outputDirectory, true);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (error instanceof TranspileOutputError)
|
|
194
|
+
throw error;
|
|
195
|
+
throw new TranspileOutputError('AMX6001', `Output preflight failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
196
|
+
}
|
|
197
|
+
if (!plan.rootIdentity)
|
|
198
|
+
outputError('AMX6001', 'A graph write plan requires an existing output directory');
|
|
199
|
+
return Object.freeze({
|
|
200
|
+
outputDirectory: plan.root,
|
|
201
|
+
entryModuleId: result.entryModuleId,
|
|
202
|
+
graphHash: graphHash(result),
|
|
203
|
+
rootIdentity: Object.freeze({ ...plan.rootIdentity }),
|
|
204
|
+
targets: Object.freeze(plan.targets.map(target => Object.freeze({
|
|
205
|
+
outputPath: target.module.outputPath,
|
|
206
|
+
exists: target.exists,
|
|
207
|
+
...(target.original ? {
|
|
208
|
+
sha256: target.original.sha256,
|
|
209
|
+
size: target.original.size,
|
|
210
|
+
mode: target.original.mode,
|
|
211
|
+
modifiedAt: target.original.modifiedAt
|
|
212
|
+
} : {})
|
|
213
|
+
})))
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function originalWasRestored(target) {
|
|
217
|
+
if (!target.original)
|
|
218
|
+
return false;
|
|
219
|
+
const stat = statSync(target.absolutePath);
|
|
220
|
+
return stat.isFile() && stat.size === target.original.size
|
|
221
|
+
&& stat.mode === target.original.mode && stat.mtimeMs === target.original.modifiedAt
|
|
222
|
+
&& sha256(readFileSync(target.absolutePath)) === target.original.sha256;
|
|
223
|
+
}
|
|
224
|
+
function removeCreatedDirectories(created) {
|
|
225
|
+
for (const directory of [...created].reverse()) {
|
|
226
|
+
try {
|
|
227
|
+
rmdirSync(directory);
|
|
228
|
+
}
|
|
229
|
+
catch { /* Keep non-empty or inaccessible directories. */ }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function pathStates(states) {
|
|
233
|
+
return [...states.values()].sort((left, right) => left.outputPath.localeCompare(right.outputPath));
|
|
234
|
+
}
|
|
235
|
+
export function writeTranspiledGraph(result, outputDirectory, options = {}) {
|
|
236
|
+
let plan;
|
|
237
|
+
try {
|
|
238
|
+
plan = preflight(result.modules, result.entryModuleId, outputDirectory, options.overwrite === true);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
if (error instanceof TranspileOutputError)
|
|
242
|
+
throw error;
|
|
243
|
+
throw new TranspileOutputError('AMX6001', `Output preflight failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
244
|
+
}
|
|
245
|
+
if (options.expectedPlan)
|
|
246
|
+
assertExpectedPlan(result, options.expectedPlan, plan);
|
|
247
|
+
const createdDirectories = [];
|
|
248
|
+
for (const directory of missingDirectories(plan.root)) {
|
|
249
|
+
try {
|
|
250
|
+
mkdirSync(directory);
|
|
251
|
+
createdDirectories.push(directory);
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
removeCreatedDirectories(createdDirectories);
|
|
255
|
+
throw new TranspileOutputError('AMX6002', `Could not create output directory: ${error instanceof Error ? error.message : String(error)}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (realpathSync(plan.root) !== plan.root) {
|
|
259
|
+
removeCreatedDirectories(createdDirectories);
|
|
260
|
+
outputError('AMX6001', 'Output directory changed during preflight');
|
|
261
|
+
}
|
|
262
|
+
let stageDirectory;
|
|
263
|
+
try {
|
|
264
|
+
stageDirectory = mkdtempSync(path.join(plan.root, '.openamx-transpile-'));
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
removeCreatedDirectories(createdDirectories);
|
|
268
|
+
throw new TranspileOutputError('AMX6002', `Could not create output staging directory: ${error instanceof Error ? error.message : String(error)}`);
|
|
269
|
+
}
|
|
270
|
+
const states = new Map();
|
|
271
|
+
const stagedPaths = new Map();
|
|
272
|
+
const backups = new Map();
|
|
273
|
+
const published = new Set();
|
|
274
|
+
try {
|
|
275
|
+
for (const target of plan.targets) {
|
|
276
|
+
options.failureInjector?.('stage', target.module.outputPath);
|
|
277
|
+
const stagedPath = path.join(stageDirectory, 'staged', ...target.module.outputPath.split('/'));
|
|
278
|
+
mkdirSync(path.dirname(stagedPath), { recursive: true });
|
|
279
|
+
const bytes = Buffer.from(target.module.code, 'utf8');
|
|
280
|
+
writeFileSync(stagedPath, bytes, { flag: 'wx' });
|
|
281
|
+
if (sha256(readFileSync(stagedPath)) !== sha256(bytes))
|
|
282
|
+
throw new Error(`Staged content verification failed for '${target.module.outputPath}'`);
|
|
283
|
+
stagedPaths.set(target.module.outputPath, stagedPath);
|
|
284
|
+
states.set(target.module.outputPath, { outputPath: target.module.outputPath, state: 'staged' });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
289
|
+
rmSync(stageDirectory, { recursive: true, force: true });
|
|
290
|
+
removeCreatedDirectories(createdDirectories);
|
|
291
|
+
throw new TranspileOutputError('AMX6002', `Failed while staging generated graph: ${message}`, pathStates(states));
|
|
292
|
+
}
|
|
293
|
+
if (options.expectedPlan) {
|
|
294
|
+
try {
|
|
295
|
+
const currentPlan = preflight(result.modules, result.entryModuleId, outputDirectory, true);
|
|
296
|
+
assertExpectedPlan(result, options.expectedPlan, currentPlan);
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
rmSync(stageDirectory, { recursive: true, force: true });
|
|
300
|
+
removeCreatedDirectories(createdDirectories);
|
|
301
|
+
if (error instanceof TranspileOutputError)
|
|
302
|
+
throw error;
|
|
303
|
+
throw new TranspileOutputError('AMX6001', `Output plan revalidation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
for (const target of plan.targets) {
|
|
308
|
+
for (const directory of missingDirectories(path.dirname(target.absolutePath))) {
|
|
309
|
+
if (!lstatIfExists(directory)) {
|
|
310
|
+
mkdirSync(directory);
|
|
311
|
+
createdDirectories.push(directory);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
for (const target of plan.targets) {
|
|
316
|
+
const outputPath = target.module.outputPath;
|
|
317
|
+
options.failureInjector?.('publish', outputPath);
|
|
318
|
+
if (target.exists) {
|
|
319
|
+
const backupPath = path.join(stageDirectory, 'backups', ...outputPath.split('/'));
|
|
320
|
+
mkdirSync(path.dirname(backupPath), { recursive: true });
|
|
321
|
+
renameSync(target.absolutePath, backupPath);
|
|
322
|
+
backups.set(outputPath, backupPath);
|
|
323
|
+
}
|
|
324
|
+
renameSync(stagedPaths.get(outputPath), target.absolutePath);
|
|
325
|
+
published.add(outputPath);
|
|
326
|
+
states.set(outputPath, { outputPath, state: 'published' });
|
|
327
|
+
}
|
|
328
|
+
for (const target of plan.targets) {
|
|
329
|
+
const actual = readFileSync(target.absolutePath);
|
|
330
|
+
const expected = Buffer.from(target.module.code, 'utf8');
|
|
331
|
+
if (sha256(actual) !== sha256(expected))
|
|
332
|
+
throw new Error(`Published content verification failed for '${target.module.outputPath}'`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
const primaryMessage = error instanceof Error ? error.message : String(error);
|
|
337
|
+
const rollbackErrors = [];
|
|
338
|
+
for (const target of [...plan.targets].reverse()) {
|
|
339
|
+
const outputPath = target.module.outputPath;
|
|
340
|
+
const backupPath = backups.get(outputPath);
|
|
341
|
+
if (!published.has(outputPath) && !backupPath)
|
|
342
|
+
continue;
|
|
343
|
+
try {
|
|
344
|
+
options.failureInjector?.('rollback', outputPath);
|
|
345
|
+
if (published.has(outputPath) && lstatIfExists(target.absolutePath)) {
|
|
346
|
+
rmSync(target.absolutePath, { force: true });
|
|
347
|
+
}
|
|
348
|
+
if (backupPath) {
|
|
349
|
+
renameSync(backupPath, target.absolutePath);
|
|
350
|
+
if (!originalWasRestored(target))
|
|
351
|
+
throw new Error(`Original destination verification failed for '${outputPath}'`);
|
|
352
|
+
}
|
|
353
|
+
else if (published.has(outputPath) && lstatIfExists(target.absolutePath)) {
|
|
354
|
+
throw new Error(`New destination could not be removed for '${outputPath}'`);
|
|
355
|
+
}
|
|
356
|
+
states.set(outputPath, { outputPath, state: 'restored' });
|
|
357
|
+
}
|
|
358
|
+
catch (rollbackError) {
|
|
359
|
+
const detail = rollbackError instanceof Error ? rollbackError.message : String(rollbackError);
|
|
360
|
+
rollbackErrors.push(`${outputPath}: ${detail}`);
|
|
361
|
+
states.set(outputPath, { outputPath, state: 'unrecovered', detail });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const unrecovered = [...states.values()].some(state => state.state === 'unrecovered');
|
|
365
|
+
if (unrecovered) {
|
|
366
|
+
throw new TranspileOutputError('AMX6002', `Graph publication failed: ${primaryMessage}; rollback incomplete: ${rollbackErrors.join('; ')}`, pathStates(states), stageDirectory);
|
|
367
|
+
}
|
|
368
|
+
rmSync(stageDirectory, { recursive: true, force: true });
|
|
369
|
+
removeCreatedDirectories(createdDirectories);
|
|
370
|
+
throw new TranspileOutputError('AMX6002', `Graph publication failed and rollback was verified: ${primaryMessage}`, pathStates(states));
|
|
371
|
+
}
|
|
372
|
+
rmSync(stageDirectory, { recursive: true, force: true });
|
|
373
|
+
const entry = result.modules.find(module => module.moduleId === result.entryModuleId);
|
|
374
|
+
return {
|
|
375
|
+
entryPath: path.join(plan.root, ...entry.outputPath.split('/')),
|
|
376
|
+
outputPaths: plan.targets.map(target => target.module.outputPath)
|
|
377
|
+
};
|
|
378
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const sourceLineBreak = /\r\n|[\r\n\u2028\u2029]/;
|
|
2
|
+
export function normalizeParserLineSeparators(source) {
|
|
3
|
+
return source.replace(/\r\n|[\r\u2028\u2029]/g, '\n');
|
|
4
|
+
}
|
|
5
|
+
export function safeNarrativeComments(source) {
|
|
6
|
+
return source.split(sourceLineBreak).map(line => `// ${line}`);
|
|
7
|
+
}
|
|
8
|
+
export function rawFrontMatterComments(source) {
|
|
9
|
+
const lines = source.split(sourceLineBreak);
|
|
10
|
+
if (lines[0]?.trim() !== '---')
|
|
11
|
+
return [];
|
|
12
|
+
const closingIndex = lines.findIndex((line, index) => index > 0 && line.trim() === '---');
|
|
13
|
+
if (closingIndex < 0)
|
|
14
|
+
return [];
|
|
15
|
+
return safeNarrativeComments(lines.slice(0, closingIndex + 1).join('\n'));
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|