screw-up 1.17.0 → 1.18.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 CHANGED
@@ -49,6 +49,10 @@ To insert banner header each bundled source files (`dist/index.js` and etc.):
49
49
  You may have noticed the line `git.commit.hash:`. That's right, if your project is managed by Git (it is, right?), you can also insert commit IDs, branch information, and tag information.
50
50
  Most importantly, if a version is applied to a Git tag, you can automatically reflect that version tag in the `version` field of `package.json`. In other words, you can manage version numbers using only Git tags!
51
51
 
52
+ This calculates the version number by measuring the commit height to the current HEAD based on the last applied version tag.
53
+
54
+ ![git-versioning](./images/git-versioning.png)
55
+
52
56
  Instead of using `npm pack`, you can use the CLI tool `screw-up` to generate packages, which will automatically apply the collected metadata to the NPM package's `package.json`:
53
57
 
54
58
  ```bash
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.17.0
3
+ * version: 1.18.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: 05a9f2e0dec5249126f020eee1d57f6ff8767096
8
+ * git.commit.hash: 104b6e6ab47e8c328ae5d6883f7931b0eea4f5cd
9
9
  */
10
10
 
11
11
  import { Logger } from './internal.js';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.17.0
3
+ * version: 1.18.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: 05a9f2e0dec5249126f020eee1d57f6ff8767096
8
+ * git.commit.hash: 104b6e6ab47e8c328ae5d6883f7931b0eea4f5cd
9
9
  */
10
10
 
11
11
  import { Logger } from './internal';
package/dist/cli.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.17.0
3
+ * version: 1.18.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: 05a9f2e0dec5249126f020eee1d57f6ff8767096
8
+ * git.commit.hash: 104b6e6ab47e8c328ae5d6883f7931b0eea4f5cd
9
9
  */
10
10
 
11
11
  import { Logger } from './internal';
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAypBpC,eAAO,MAAM,OAAO,GAClB,MAAM,MAAM,EAAE,EACd,QAAQ,MAAM,KACb,OAAO,CAAC,MAAM,CA8BhB,CAAC"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;AAiBA,OAAO,EAAE,MAAM,EAA0B,MAAM,YAAY,CAAC;AAkyB5D,eAAO,MAAM,OAAO,GAClB,MAAM,MAAM,EAAE,EACd,QAAQ,MAAM,KACb,OAAO,CAAC,MAAM,CAgChB,CAAC"}
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.17.0
3
+ * version: 1.18.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: 05a9f2e0dec5249126f020eee1d57f6ff8767096
8
+ * git.commit.hash: 104b6e6ab47e8c328ae5d6883f7931b0eea4f5cd
9
9
  */
10
10
 
11
11
  import { Logger } from './internal.js';
@@ -1,18 +1,18 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.17.0
3
+ * version: 1.18.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: 05a9f2e0dec5249126f020eee1d57f6ff8767096
8
+ * git.commit.hash: 104b6e6ab47e8c328ae5d6883f7931b0eea4f5cd
9
9
  */
10
10
 
11
11
  export declare const name = "screw-up";
12
- export declare const version = "1.17.0";
12
+ export declare const version = "1.18.0";
13
13
  export declare const description = "Simply package metadata inserter on Vite plugin";
14
14
  export declare const author = "Kouji Matsui (@kekyo@mi.kekyo.net)";
15
15
  export declare const license = "MIT";
16
16
  export declare const repository_url = "https://github.com/kekyo/screw-up.git";
17
- export declare const git_commit_hash = "05a9f2e0dec5249126f020eee1d57f6ff8767096";
17
+ export declare const git_commit_hash = "104b6e6ab47e8c328ae5d6883f7931b0eea4f5cd";
18
18
  //# sourceMappingURL=packageMetadata.d.ts.map
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.17.0
3
+ * version: 1.18.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: 05a9f2e0dec5249126f020eee1d57f6ff8767096
8
+ * git.commit.hash: 104b6e6ab47e8c328ae5d6883f7931b0eea4f5cd
9
9
  */
10
10
 
11
11
  import { TagInfo, Version } from './analyzer';
package/dist/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  /*!
3
3
  * name: screw-up
4
- * version: 1.17.0
4
+ * version: 1.18.0
5
5
  * description: Simply package metadata inserter on Vite plugin
6
6
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
7
7
  * license: MIT
8
8
  * repository.url: https://github.com/kekyo/screw-up.git
9
- * git.commit.hash: 05a9f2e0dec5249126f020eee1d57f6ff8767096
9
+ * git.commit.hash: 104b6e6ab47e8c328ae5d6883f7931b0eea4f5cd
10
10
  */
11
11
  const fs = require("fs/promises");
12
12
  const fs$1 = require("fs");
13
13
  const path = require("path");
14
- const packageMetadata = require("./packageMetadata-DdvLnmBC.cjs");
14
+ const packageMetadata = require("./packageMetadata-B-eWBZ6y.cjs");
15
15
  /*!
16
16
  * name: async-primitives
17
17
  * version: 1.2.0
@@ -227,40 +227,6 @@ const mergeBanners = (currentBanner, existingBanner) => {
227
227
  const currentWithNewline = ensureTrailingNewline(currentBanner, newlineSeq);
228
228
  return `${currentWithNewline}${existingBanner}`;
229
229
  };
230
- const sanitizeKey = (key) => {
231
- return key.replace(/[^a-zA-Z0-9_]/g, "_").replace(/^(\d)/, "_$1");
232
- };
233
- const generateMetadataFileContent = (metadata, outputKeys) => {
234
- const lines = [];
235
- const exportedIdentifiers = [];
236
- lines.push("// @ts-nocheck");
237
- lines.push("// This file is auto-generated by screw-up plugin");
238
- lines.push("// Do not edit manually");
239
- lines.push("");
240
- for (const key of outputKeys) {
241
- const value = metadata[key];
242
- if (value) {
243
- const sanitizedKey = sanitizeKey(key);
244
- const escapedValue = JSON.stringify(value);
245
- lines.push(`export const ${sanitizedKey} = ${escapedValue};`);
246
- exportedIdentifiers.push(sanitizedKey);
247
- }
248
- }
249
- lines.push("");
250
- return { content: lines.join("\n"), exportedIdentifiers };
251
- };
252
- const generateMetadataTypeFileContent = (outputKeys) => {
253
- const lines = [];
254
- lines.push("// This file is auto-generated by screw-up plugin");
255
- lines.push("// Do not edit manually");
256
- lines.push("");
257
- for (const key of outputKeys) {
258
- const sanitizedKey = sanitizeKey(key);
259
- lines.push(`export declare const ${sanitizedKey}: string;`);
260
- }
261
- lines.push("");
262
- return lines.join("\n");
263
- };
264
230
  const countInsertedLines = (bannerWithTrailingNewline) => {
265
231
  return bannerWithTrailingNewline.split("\n").length - 1;
266
232
  };
@@ -302,7 +268,6 @@ const screwUp = (options = {}) => {
302
268
  assetFilters = ["\\.d\\.ts$"],
303
269
  outputMetadataFile = false,
304
270
  outputMetadataFilePath = "src/generated/packageMetadata.ts",
305
- outputMetadataFileTypePath,
306
271
  outputMetadataKeys = [
307
272
  "name",
308
273
  "version",
@@ -317,7 +282,6 @@ const screwUp = (options = {}) => {
317
282
  insertMetadataBanner = true
318
283
  } = options;
319
284
  const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
320
- const resolvedOutputMetadataTypeFilePath = outputMetadataFileTypePath || outputMetadataFilePath.replace(/\.ts$/, ".d.ts");
321
285
  const generateMetadataSourceLocker = createMutex();
322
286
  const loggerPrefix = `${packageMetadata.name}-vite`;
323
287
  let logger = packageMetadata.createConsoleLogger(loggerPrefix);
@@ -325,50 +289,6 @@ const screwUp = (options = {}) => {
325
289
  let metadata;
326
290
  let projectRoot;
327
291
  let fetchGitMetadata = () => Promise.resolve({});
328
- const writeFileIfChanged = async (filePath, content, description) => {
329
- try {
330
- let shouldWrite = !fs$1.existsSync(filePath);
331
- if (!shouldWrite) {
332
- try {
333
- const existingContent = await fs.readFile(filePath, "utf-8");
334
- shouldWrite = existingContent !== content;
335
- } catch (e) {
336
- shouldWrite = true;
337
- }
338
- }
339
- if (shouldWrite) {
340
- await fs.mkdir(path.dirname(filePath), { recursive: true });
341
- await fs.writeFile(filePath, content);
342
- return true;
343
- } else {
344
- return false;
345
- }
346
- } catch (error) {
347
- logger.warn(`Failed to write ${description}: ${filePath}: ${error}`);
348
- return false;
349
- }
350
- };
351
- const ensureMetadataGitignore = async (metadataSourcePath) => {
352
- const metadataDirectory = path.dirname(metadataSourcePath);
353
- const gitignorePath = path.join(metadataDirectory, ".gitignore");
354
- if (fs$1.existsSync(gitignorePath)) {
355
- return false;
356
- }
357
- try {
358
- await fs.mkdir(metadataDirectory, { recursive: true });
359
- const metadataFileName = path.basename(metadataSourcePath);
360
- const gitignoreContent = `# Auto-generated by screw-up plugin
361
- ${metadataFileName}
362
- `;
363
- await fs.writeFile(gitignorePath, gitignoreContent);
364
- return true;
365
- } catch (error) {
366
- logger.warn(
367
- `Failed to write .gitignore for metadata source: ${gitignorePath}: ${error}`
368
- );
369
- return false;
370
- }
371
- };
372
292
  const generateMetadataSourceFiles = async () => {
373
293
  const result = await packageMetadata.resolvePackageMetadata(
374
294
  projectRoot,
@@ -379,25 +299,22 @@ ${metadataFileName}
379
299
  metadata = result.metadata;
380
300
  banner = generateBanner(metadata, outputKeys);
381
301
  if (outputMetadataFile) {
382
- const { content: metadataSourceContent, exportedIdentifiers } = generateMetadataFileContent(metadata, outputMetadataKeys);
302
+ const metadataSourceContent = packageMetadata.generateMetadataFileContent(
303
+ metadata,
304
+ outputMetadataKeys
305
+ );
383
306
  const metadataSourcePath = path.join(projectRoot, outputMetadataFilePath);
384
- const metadataWritten = await writeFileIfChanged(
307
+ const metadataWritten = await packageMetadata.writeFileIfChanged(
385
308
  metadataSourcePath,
386
309
  metadataSourceContent,
387
- "metadata source file"
388
- );
389
- const metadataTypeContent = generateMetadataTypeFileContent(exportedIdentifiers);
390
- const metadataTypePath = path.join(
391
- projectRoot,
392
- resolvedOutputMetadataTypeFilePath
393
- );
394
- const metadataTypeWritten = await writeFileIfChanged(
395
- metadataTypePath,
396
- metadataTypeContent,
397
- "metadata type definition file"
310
+ "metadata source file",
311
+ logger
398
312
  );
399
313
  if (fs$1.existsSync(metadataSourcePath)) {
400
- const gitignoreWritten = await ensureMetadataGitignore(metadataSourcePath);
314
+ const gitignoreWritten = await packageMetadata.ensureMetadataGitignore(
315
+ metadataSourcePath,
316
+ logger
317
+ );
401
318
  if (gitignoreWritten) {
402
319
  logger.info(
403
320
  `generateMetadataSourceFile: .gitignore is generated: ${path.join(
@@ -407,27 +324,7 @@ ${metadataFileName}
407
324
  );
408
325
  }
409
326
  }
410
- if (metadataTypeWritten) {
411
- logger.info(
412
- `generateMetadataSourceFile: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
413
- );
414
- }
415
- return metadataWritten || metadataTypeWritten;
416
- }
417
- return false;
418
- };
419
- const generateMetadataTypeDefinitionFileFromKeys = async (keys) => {
420
- if (outputMetadataFile) {
421
- const metadataTypeContent = generateMetadataTypeFileContent(keys);
422
- const metadataTypePath = path.join(
423
- projectRoot,
424
- resolvedOutputMetadataTypeFilePath
425
- );
426
- return await writeFileIfChanged(
427
- metadataTypePath,
428
- metadataTypeContent,
429
- "metadata type definition file"
430
- );
327
+ return metadataWritten;
431
328
  }
432
329
  return false;
433
330
  };
@@ -439,14 +336,12 @@ ${metadataFileName}
439
336
  keys.forEach((key) => {
440
337
  dummyMetadata[key] = "[Require first build]";
441
338
  });
442
- const { content: dummyContent } = generateMetadataFileContent(
443
- dummyMetadata,
444
- keys
445
- );
446
- return await writeFileIfChanged(
339
+ const dummyContent = packageMetadata.generateMetadataFileContent(dummyMetadata, keys);
340
+ return await packageMetadata.writeFileIfChanged(
447
341
  metadataSourcePath,
448
342
  dummyContent,
449
- "dummy metadata source file"
343
+ "dummy metadata source file",
344
+ logger
450
345
  );
451
346
  }
452
347
  }
@@ -461,11 +356,6 @@ ${metadataFileName}
461
356
  applyToEnvironment: async (penv) => {
462
357
  logger.info(`${packageMetadata.version}-${packageMetadata.git_commit_hash}: Started.`);
463
358
  projectRoot = penv.config.root;
464
- if (projectRoot && await generateMetadataTypeDefinitionFileFromKeys(outputMetadataKeys)) {
465
- logger.info(
466
- `applyToEnvironment: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
467
- );
468
- }
469
359
  if (projectRoot && await generateMetadataFileFromKeys(outputMetadataKeys)) {
470
360
  logger.info(
471
361
  `applyToEnvironment: Dummy metadata source file is generated: ${outputMetadataFilePath}`