Skip to content

Commit 1d2c1f3

Browse files
committed
d
1 parent b31d9c0 commit 1d2c1f3

4 files changed

Lines changed: 40 additions & 14 deletions

File tree

TRANSPILATION.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ It is generally looking into all files it can see except obvious exclusions like
2121

2222
Is more flexible which can switch between transpiling and bundling for special cases
2323

24+
See
25+
pages/bash/xx/xx.node.cjs
26+
that is good example how to override esbuild setup for individual files
27+
2428
# esbuild-node.sh
2529

2630
There is one more transpiler just for one use case to work with node.

es.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ if (!PRODUCE_GITIGNORE) {
9191

9292
var SLASH = "/";
9393

94-
async function stripTypes(filePath: string): Promise<string | undefined> {
94+
async function stripTypes(filePath: string): Promise<{ outPath: string | undefined; config: any } | undefined> {
9595
try {
9696
const source = readFileSync(filePath, "utf8");
9797
const startMarker = "/** @es.ts";
@@ -133,7 +133,7 @@ async function stripTypes(filePath: string): Promise<string | undefined> {
133133
}
134134

135135
// 3. Merge top-level config fields (excluding tool-specific ones)
136-
const { mode, extension: _ext, setup, options, ...rest } = config;
136+
const { mode, extension: _ext, setup, options, cliarguments, ...rest } = config;
137137
const mergedOptions: any = {
138138
...baseOptions,
139139
...rest,
@@ -200,10 +200,10 @@ async function stripTypes(filePath: string): Promise<string | undefined> {
200200
}
201201
}
202202

203-
if (!PRODUCE_GITIGNORE && firstOutPath) {
204-
console.log(`${buildMode === "bundle" ? "Bundled" : "Transpiled"} (esbuild): ${filePath} -> ${firstOutPath}`);
205-
}
206-
return firstOutPath;
203+
return {
204+
outPath: firstOutPath,
205+
config,
206+
};
207207
} catch (err: unknown) {
208208
hasError = true;
209209
const message = err instanceof Error ? err.message : String(err);
@@ -311,6 +311,9 @@ Description:
311311
312312
// Use 'undefined' to unset a default and let esbuild decide:
313313
minify: undefined,
314+
315+
// Overriding command line arguments:
316+
"cliarguments": ["--produce-gitignore"], // override global arguments for this file
314317
}
315318
@es.ts *${SLASH}
316319
@@ -336,7 +339,8 @@ const rl = createInterface({
336339

337340
let processedCount: number = 0;
338341
let hasError: boolean = false;
339-
const gitignorePaths: string[] = [];
342+
const gitignorePaths: string[] = []; // paths to produce in stdout
343+
const updatePaths: string[] = []; // paths to actually update in .gitignore
340344
const semaphore = new Semaphore(ES_PARALLEL);
341345
const activeTasks = new Set<Promise<void>>();
342346

@@ -349,10 +353,28 @@ for await (const line of rl) {
349353
// Start the task and keep track of it in the activeTasks Set
350354
const task: Promise<void> = (async () => {
351355
try {
352-
let outPath = await stripTypes(file);
353-
if (PRODUCE_GITIGNORE && outPath) {
354-
outPath = relative(gitRoot, outPath);
355-
gitignorePaths.push(outPath);
356+
const result = await stripTypes(file);
357+
if (result && result.outPath) {
358+
const { outPath, config } = result;
359+
const buildMode = config.mode || (CONFIG.bundle ? "bundle" : "transform");
360+
if (!PRODUCE_GITIGNORE) {
361+
console.log(`${buildMode === "bundle" ? "Bundled" : "Transpiled"} (esbuild): ${file} -> ${outPath}`);
362+
}
363+
364+
const localArgs = Array.isArray(config.cliarguments)
365+
? config.cliarguments
366+
: args;
367+
368+
const localProduceGitignore = localArgs.includes("--produce-gitignore");
369+
const localUpdateGitignore = localArgs.includes("--update");
370+
371+
if (localProduceGitignore) {
372+
const relPath = relative(gitRoot, outPath);
373+
gitignorePaths.push(relPath);
374+
if (localUpdateGitignore) {
375+
updatePaths.push(relPath);
376+
}
377+
}
356378
}
357379
} finally {
358380
semaphore.release();
@@ -372,7 +394,7 @@ if (PRODUCE_GITIGNORE && gitignorePaths.length > 0) {
372394
let pathsToLog = gitignorePaths;
373395

374396
if (UPDATE_GITIGNORE) {
375-
pathsToLog = updateGitignoreFile(gitRoot, startMarker, endMarker, gitignorePaths);
397+
pathsToLog = updateGitignoreFile(gitRoot, startMarker, endMarker, updatePaths);
376398
}
377399

378400
const content = [startMarker, ...pathsToLog.sort(), endMarker].join("\n");

pages/bash/xx/xx.lock.gits-update-config.node.cjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
outExtension: {
1616
".js": ".cjs",
1717
},
18-
options: {
19-
}
18+
"cliarguments": ["--produce-gitignore"], // override global arguments for this file
2019
}
2120
@es.ts */
2221
/**

pages/bash/xx/xx.node.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
outExtension: {
1616
".js": ".cjs",
1717
},
18+
"cliarguments": ["--produce-gitignore"], // override global arguments for this file
1819
}
1920
@es.ts */
2021
/**

0 commit comments

Comments
 (0)