screw-up 1.17.0 → 1.19.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 +4 -0
- package/dist/analyzer.d.ts +2 -2
- package/dist/cli-internal.d.ts +10 -3
- package/dist/cli-internal.d.ts.map +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/fast-tags.d.ts +2 -2
- package/dist/generated/packageMetadata.d.ts +4 -4
- package/dist/git-operations.d.ts +2 -2
- package/dist/index.cjs +33 -133
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -133
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/main.cjs +277 -14
- package/dist/main.cjs.map +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.js +279 -16
- package/dist/main.js.map +1 -1
- package/dist/metadata-file.d.ts +22 -0
- package/dist/metadata-file.d.ts.map +1 -0
- package/dist/{packageMetadata-DdvLnmBC.cjs → packageMetadata-DXwK6bb8.cjs} +73 -5
- package/dist/packageMetadata-DXwK6bb8.cjs.map +1 -0
- package/dist/{packageMetadata-DgMEVI8P.js → packageMetadata-DlkAQe0j.js} +79 -11
- package/dist/packageMetadata-DlkAQe0j.js.map +1 -0
- package/dist/types.d.ts +2 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/vite-plugin.d.ts +2 -2
- package/dist/vite-plugin.d.ts.map +1 -1
- package/images/git-versioning.png +0 -0
- package/package.json +10 -9
- package/dist/packageMetadata-DdvLnmBC.cjs.map +0 -1
- package/dist/packageMetadata-DgMEVI8P.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: screw-up
|
|
3
|
-
* version: 1.
|
|
3
|
+
* version: 1.19.0
|
|
4
4
|
* description: Simply package metadata inserter on Vite plugin
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/screw-up.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: b86321865390ff8dc11c118f46a8e0ba8b67aa9c
|
|
9
9
|
*/
|
|
10
|
-
import { readdir, readFile, writeFile
|
|
10
|
+
import { readdir, readFile, writeFile } from "fs/promises";
|
|
11
11
|
import { existsSync } from "fs";
|
|
12
|
-
import { join, dirname
|
|
13
|
-
import { c as createConsoleLogger, n as name, g as getFetchGitMetadata, v as version, a as git_commit_hash, r as resolvePackageMetadata } from "./packageMetadata-
|
|
12
|
+
import { join, dirname } from "path";
|
|
13
|
+
import { c as createConsoleLogger, n as name, g as getFetchGitMetadata, v as version, a as git_commit_hash, r as resolvePackageMetadata, b as generateMetadataFileContent, w as writeFileIfChanged, e as ensureMetadataGitignore } from "./packageMetadata-DlkAQe0j.js";
|
|
14
14
|
/*!
|
|
15
15
|
* name: async-primitives
|
|
16
|
-
* version: 1.
|
|
16
|
+
* version: 1.5.0
|
|
17
17
|
* description: A collection of primitive functions for asynchronous operations
|
|
18
18
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
19
19
|
* license: MIT
|
|
20
20
|
* repository.url: https://github.com/kekyo/async-primitives.git
|
|
21
|
-
* git.commit.hash:
|
|
21
|
+
* git.commit.hash: cd35465b7e9b9945049186e7eaeecc0bfba65766
|
|
22
22
|
*/
|
|
23
23
|
const __NOOP_HANDLER = () => {
|
|
24
24
|
};
|
|
@@ -26,13 +26,22 @@ const __NOOP_RELEASABLE = {
|
|
|
26
26
|
release: __NOOP_HANDLER,
|
|
27
27
|
[Symbol.dispose]: __NOOP_HANDLER
|
|
28
28
|
};
|
|
29
|
+
const toAbortError = (reason) => {
|
|
30
|
+
if (reason instanceof Error) {
|
|
31
|
+
return reason;
|
|
32
|
+
}
|
|
33
|
+
if (typeof reason === "string") {
|
|
34
|
+
return new Error(reason);
|
|
35
|
+
}
|
|
36
|
+
return new Error("Operation aborted");
|
|
37
|
+
};
|
|
29
38
|
const onAbort = (signal, callback) => {
|
|
30
39
|
if (!signal) {
|
|
31
40
|
return __NOOP_RELEASABLE;
|
|
32
41
|
}
|
|
33
42
|
if (signal.aborted) {
|
|
34
43
|
try {
|
|
35
|
-
callback();
|
|
44
|
+
callback(toAbortError(signal.reason));
|
|
36
45
|
} catch (error) {
|
|
37
46
|
console.warn("AbortHook callback error: ", error);
|
|
38
47
|
}
|
|
@@ -41,10 +50,11 @@ const onAbort = (signal, callback) => {
|
|
|
41
50
|
let abortHandler;
|
|
42
51
|
abortHandler = () => {
|
|
43
52
|
if (abortHandler) {
|
|
53
|
+
const reason = signal.reason;
|
|
44
54
|
signal.removeEventListener("abort", abortHandler);
|
|
45
55
|
abortHandler = void 0;
|
|
46
56
|
try {
|
|
47
|
-
callback();
|
|
57
|
+
callback(toAbortError(reason));
|
|
48
58
|
} catch (error) {
|
|
49
59
|
console.warn("AbortHook callback error: ", error);
|
|
50
60
|
}
|
|
@@ -226,40 +236,6 @@ const mergeBanners = (currentBanner, existingBanner) => {
|
|
|
226
236
|
const currentWithNewline = ensureTrailingNewline(currentBanner, newlineSeq);
|
|
227
237
|
return `${currentWithNewline}${existingBanner}`;
|
|
228
238
|
};
|
|
229
|
-
const sanitizeKey = (key) => {
|
|
230
|
-
return key.replace(/[^a-zA-Z0-9_]/g, "_").replace(/^(\d)/, "_$1");
|
|
231
|
-
};
|
|
232
|
-
const generateMetadataFileContent = (metadata, outputKeys) => {
|
|
233
|
-
const lines = [];
|
|
234
|
-
const exportedIdentifiers = [];
|
|
235
|
-
lines.push("// @ts-nocheck");
|
|
236
|
-
lines.push("// This file is auto-generated by screw-up plugin");
|
|
237
|
-
lines.push("// Do not edit manually");
|
|
238
|
-
lines.push("");
|
|
239
|
-
for (const key of outputKeys) {
|
|
240
|
-
const value = metadata[key];
|
|
241
|
-
if (value) {
|
|
242
|
-
const sanitizedKey = sanitizeKey(key);
|
|
243
|
-
const escapedValue = JSON.stringify(value);
|
|
244
|
-
lines.push(`export const ${sanitizedKey} = ${escapedValue};`);
|
|
245
|
-
exportedIdentifiers.push(sanitizedKey);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
lines.push("");
|
|
249
|
-
return { content: lines.join("\n"), exportedIdentifiers };
|
|
250
|
-
};
|
|
251
|
-
const generateMetadataTypeFileContent = (outputKeys) => {
|
|
252
|
-
const lines = [];
|
|
253
|
-
lines.push("// This file is auto-generated by screw-up plugin");
|
|
254
|
-
lines.push("// Do not edit manually");
|
|
255
|
-
lines.push("");
|
|
256
|
-
for (const key of outputKeys) {
|
|
257
|
-
const sanitizedKey = sanitizeKey(key);
|
|
258
|
-
lines.push(`export declare const ${sanitizedKey}: string;`);
|
|
259
|
-
}
|
|
260
|
-
lines.push("");
|
|
261
|
-
return lines.join("\n");
|
|
262
|
-
};
|
|
263
239
|
const countInsertedLines = (bannerWithTrailingNewline) => {
|
|
264
240
|
return bannerWithTrailingNewline.split("\n").length - 1;
|
|
265
241
|
};
|
|
@@ -301,7 +277,6 @@ const screwUp = (options = {}) => {
|
|
|
301
277
|
assetFilters = ["\\.d\\.ts$"],
|
|
302
278
|
outputMetadataFile = false,
|
|
303
279
|
outputMetadataFilePath = "src/generated/packageMetadata.ts",
|
|
304
|
-
outputMetadataFileTypePath,
|
|
305
280
|
outputMetadataKeys = [
|
|
306
281
|
"name",
|
|
307
282
|
"version",
|
|
@@ -316,7 +291,6 @@ const screwUp = (options = {}) => {
|
|
|
316
291
|
insertMetadataBanner = true
|
|
317
292
|
} = options;
|
|
318
293
|
const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
|
|
319
|
-
const resolvedOutputMetadataTypeFilePath = outputMetadataFileTypePath || outputMetadataFilePath.replace(/\.ts$/, ".d.ts");
|
|
320
294
|
const generateMetadataSourceLocker = createMutex();
|
|
321
295
|
const loggerPrefix = `${name}-vite`;
|
|
322
296
|
let logger = createConsoleLogger(loggerPrefix);
|
|
@@ -324,50 +298,6 @@ const screwUp = (options = {}) => {
|
|
|
324
298
|
let metadata;
|
|
325
299
|
let projectRoot;
|
|
326
300
|
let fetchGitMetadata = () => Promise.resolve({});
|
|
327
|
-
const writeFileIfChanged = async (filePath, content, description) => {
|
|
328
|
-
try {
|
|
329
|
-
let shouldWrite = !existsSync(filePath);
|
|
330
|
-
if (!shouldWrite) {
|
|
331
|
-
try {
|
|
332
|
-
const existingContent = await readFile(filePath, "utf-8");
|
|
333
|
-
shouldWrite = existingContent !== content;
|
|
334
|
-
} catch (e) {
|
|
335
|
-
shouldWrite = true;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
if (shouldWrite) {
|
|
339
|
-
await mkdir(dirname(filePath), { recursive: true });
|
|
340
|
-
await writeFile(filePath, content);
|
|
341
|
-
return true;
|
|
342
|
-
} else {
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
} catch (error) {
|
|
346
|
-
logger.warn(`Failed to write ${description}: ${filePath}: ${error}`);
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
const ensureMetadataGitignore = async (metadataSourcePath) => {
|
|
351
|
-
const metadataDirectory = dirname(metadataSourcePath);
|
|
352
|
-
const gitignorePath = join(metadataDirectory, ".gitignore");
|
|
353
|
-
if (existsSync(gitignorePath)) {
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
try {
|
|
357
|
-
await mkdir(metadataDirectory, { recursive: true });
|
|
358
|
-
const metadataFileName = basename(metadataSourcePath);
|
|
359
|
-
const gitignoreContent = `# Auto-generated by screw-up plugin
|
|
360
|
-
${metadataFileName}
|
|
361
|
-
`;
|
|
362
|
-
await writeFile(gitignorePath, gitignoreContent);
|
|
363
|
-
return true;
|
|
364
|
-
} catch (error) {
|
|
365
|
-
logger.warn(
|
|
366
|
-
`Failed to write .gitignore for metadata source: ${gitignorePath}: ${error}`
|
|
367
|
-
);
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
301
|
const generateMetadataSourceFiles = async () => {
|
|
372
302
|
const result = await resolvePackageMetadata(
|
|
373
303
|
projectRoot,
|
|
@@ -378,25 +308,22 @@ ${metadataFileName}
|
|
|
378
308
|
metadata = result.metadata;
|
|
379
309
|
banner = generateBanner(metadata, outputKeys);
|
|
380
310
|
if (outputMetadataFile) {
|
|
381
|
-
const
|
|
311
|
+
const metadataSourceContent = generateMetadataFileContent(
|
|
312
|
+
metadata,
|
|
313
|
+
outputMetadataKeys
|
|
314
|
+
);
|
|
382
315
|
const metadataSourcePath = join(projectRoot, outputMetadataFilePath);
|
|
383
316
|
const metadataWritten = await writeFileIfChanged(
|
|
384
317
|
metadataSourcePath,
|
|
385
318
|
metadataSourceContent,
|
|
386
|
-
"metadata source file"
|
|
387
|
-
|
|
388
|
-
const metadataTypeContent = generateMetadataTypeFileContent(exportedIdentifiers);
|
|
389
|
-
const metadataTypePath = join(
|
|
390
|
-
projectRoot,
|
|
391
|
-
resolvedOutputMetadataTypeFilePath
|
|
392
|
-
);
|
|
393
|
-
const metadataTypeWritten = await writeFileIfChanged(
|
|
394
|
-
metadataTypePath,
|
|
395
|
-
metadataTypeContent,
|
|
396
|
-
"metadata type definition file"
|
|
319
|
+
"metadata source file",
|
|
320
|
+
logger
|
|
397
321
|
);
|
|
398
322
|
if (existsSync(metadataSourcePath)) {
|
|
399
|
-
const gitignoreWritten = await ensureMetadataGitignore(
|
|
323
|
+
const gitignoreWritten = await ensureMetadataGitignore(
|
|
324
|
+
metadataSourcePath,
|
|
325
|
+
logger
|
|
326
|
+
);
|
|
400
327
|
if (gitignoreWritten) {
|
|
401
328
|
logger.info(
|
|
402
329
|
`generateMetadataSourceFile: .gitignore is generated: ${join(
|
|
@@ -406,27 +333,7 @@ ${metadataFileName}
|
|
|
406
333
|
);
|
|
407
334
|
}
|
|
408
335
|
}
|
|
409
|
-
|
|
410
|
-
logger.info(
|
|
411
|
-
`generateMetadataSourceFile: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
return metadataWritten || metadataTypeWritten;
|
|
415
|
-
}
|
|
416
|
-
return false;
|
|
417
|
-
};
|
|
418
|
-
const generateMetadataTypeDefinitionFileFromKeys = async (keys) => {
|
|
419
|
-
if (outputMetadataFile) {
|
|
420
|
-
const metadataTypeContent = generateMetadataTypeFileContent(keys);
|
|
421
|
-
const metadataTypePath = join(
|
|
422
|
-
projectRoot,
|
|
423
|
-
resolvedOutputMetadataTypeFilePath
|
|
424
|
-
);
|
|
425
|
-
return await writeFileIfChanged(
|
|
426
|
-
metadataTypePath,
|
|
427
|
-
metadataTypeContent,
|
|
428
|
-
"metadata type definition file"
|
|
429
|
-
);
|
|
336
|
+
return metadataWritten;
|
|
430
337
|
}
|
|
431
338
|
return false;
|
|
432
339
|
};
|
|
@@ -438,14 +345,12 @@ ${metadataFileName}
|
|
|
438
345
|
keys.forEach((key) => {
|
|
439
346
|
dummyMetadata[key] = "[Require first build]";
|
|
440
347
|
});
|
|
441
|
-
const
|
|
442
|
-
dummyMetadata,
|
|
443
|
-
keys
|
|
444
|
-
);
|
|
348
|
+
const dummyContent = generateMetadataFileContent(dummyMetadata, keys);
|
|
445
349
|
return await writeFileIfChanged(
|
|
446
350
|
metadataSourcePath,
|
|
447
351
|
dummyContent,
|
|
448
|
-
"dummy metadata source file"
|
|
352
|
+
"dummy metadata source file",
|
|
353
|
+
logger
|
|
449
354
|
);
|
|
450
355
|
}
|
|
451
356
|
}
|
|
@@ -460,11 +365,6 @@ ${metadataFileName}
|
|
|
460
365
|
applyToEnvironment: async (penv) => {
|
|
461
366
|
logger.info(`${version}-${git_commit_hash}: Started.`);
|
|
462
367
|
projectRoot = penv.config.root;
|
|
463
|
-
if (projectRoot && await generateMetadataTypeDefinitionFileFromKeys(outputMetadataKeys)) {
|
|
464
|
-
logger.info(
|
|
465
|
-
`applyToEnvironment: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
368
|
if (projectRoot && await generateMetadataFileFromKeys(outputMetadataKeys)) {
|
|
469
369
|
logger.info(
|
|
470
370
|
`applyToEnvironment: Dummy metadata source file is generated: ${outputMetadataFilePath}`
|