screw-up 1.8.0 → 1.10.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
@@ -70,7 +70,13 @@ my-awesome-library-2.1.0.tgz
70
70
 
71
71
  ## Documentation
72
72
 
73
- [See the repository](https://github.com/kekyo/screw-up/)
73
+ [See the repository document](https://github.com/kekyo/screw-up/).
74
+
75
+ ## Discussions and Pull Requests
76
+
77
+ For discussions, please refer to the [GitHub Discussions page](https://github.com/kekyo/screw-up/discussions). We have currently stopped issue-based discussions.
78
+
79
+ Pull requests are welcome! Please submit them as diffs against the `develop` branch and squashed changes before send.
74
80
 
75
81
  ## License
76
82
 
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.10.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: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: ed5f57c0933fcc061c70daf43aae0b41cecf358c
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.8.0
3
+ * version: 1.10.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: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: ed5f57c0933fcc061c70daf43aae0b41cecf358c
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.8.0
3
+ * version: 1.10.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: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: ed5f57c0933fcc061c70daf43aae0b41cecf358c
9
9
  */
10
10
 
11
11
  import { Logger } from './internal';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.10.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: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: ed5f57c0933fcc061c70daf43aae0b41cecf358c
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.8.0
3
+ * version: 1.10.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: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: ed5f57c0933fcc061c70daf43aae0b41cecf358c
9
9
  */
10
10
 
11
11
  export declare const name = "screw-up";
12
- export declare const version = "1.8.0";
12
+ export declare const version = "1.10.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 = "da96533e5128033ff7a45d59b1cee39e0e819533";
17
+ export declare const git_commit_hash = "ed5f57c0933fcc061c70daf43aae0b41cecf358c";
18
18
  //# sourceMappingURL=packageMetadata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageMetadata.d.ts","sourceRoot":"","sources":["../../src/generated/packageMetadata.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI,aAAa,CAAC;AAC/B,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,WAAW,oDAAoD,CAAC;AAC7E,eAAO,MAAM,MAAM,uCAAuC,CAAC;AAC3D,eAAO,MAAM,OAAO,QAAQ,CAAC;AAC7B,eAAO,MAAM,cAAc,0CAA0C,CAAC;AACtE,eAAO,MAAM,eAAe,6CAA6C,CAAC"}
1
+ {"version":3,"file":"packageMetadata.d.ts","sourceRoot":"","sources":["../../src/generated/packageMetadata.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,IAAI,aAAa,CAAC;AAC/B,eAAO,MAAM,OAAO,WAAW,CAAC;AAChC,eAAO,MAAM,WAAW,oDAAoD,CAAC;AAC7E,eAAO,MAAM,MAAM,uCAAuC,CAAC;AAC3D,eAAO,MAAM,OAAO,QAAQ,CAAC;AAC7B,eAAO,MAAM,cAAc,0CAA0C,CAAC;AACtE,eAAO,MAAM,eAAe,6CAA6C,CAAC"}
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.10.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: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: ed5f57c0933fcc061c70daf43aae0b41cecf358c
9
9
  */
10
10
 
11
11
  import { TagInfo, Version } from './analyzer';
package/dist/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.8.0
3
+ * version: 1.10.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: da96533e5128033ff7a45d59b1cee39e0e819533
8
+ * git.commit.hash: ed5f57c0933fcc061c70daf43aae0b41cecf358c
9
9
  */
10
10
  "use strict";
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-BwTlrgAe.cjs");
14
+ const packageMetadata = require("./packageMetadata-DUEevWzF.cjs");
15
15
  /*!
16
16
  * name: async-primitives
17
17
  * version: 1.2.0
@@ -203,8 +203,10 @@ const insertBannerHeader = (content, banner) => {
203
203
  const sanitizeKey = (key) => {
204
204
  return key.replace(/[^a-zA-Z0-9_]/g, "_").replace(/^(\d)/, "_$1");
205
205
  };
206
- const generateMetadataFile = (metadata, outputKeys) => {
206
+ const generateMetadataFileContent = (metadata, outputKeys) => {
207
207
  const lines = [];
208
+ const exportedIdentifiers = [];
209
+ lines.push("// @ts-nocheck");
208
210
  lines.push("// This file is auto-generated by screw-up plugin");
209
211
  lines.push("// Do not edit manually");
210
212
  lines.push("");
@@ -214,12 +216,13 @@ const generateMetadataFile = (metadata, outputKeys) => {
214
216
  const sanitizedKey = sanitizeKey(key);
215
217
  const escapedValue = JSON.stringify(value);
216
218
  lines.push(`export const ${sanitizedKey} = ${escapedValue};`);
219
+ exportedIdentifiers.push(sanitizedKey);
217
220
  }
218
221
  }
219
222
  lines.push("");
220
- return lines.join("\n");
223
+ return { content: lines.join("\n"), exportedIdentifiers };
221
224
  };
222
- const generateMetadataTypeFile = (outputKeys) => {
225
+ const generateMetadataTypeFileContent = (outputKeys) => {
223
226
  const lines = [];
224
227
  lines.push("// This file is auto-generated by screw-up plugin");
225
228
  lines.push("// Do not edit manually");
@@ -260,7 +263,7 @@ const screwUp = (options = {}) => {
260
263
  insertMetadataBanner = true
261
264
  } = options;
262
265
  const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
263
- const resolvedOutputMetadataFileTypePath = outputMetadataFileTypePath || outputMetadataFilePath.replace(/\.ts$/, ".d.ts");
266
+ const resolvedOutputMetadataTypeFilePath = outputMetadataFileTypePath || outputMetadataFilePath.replace(/\.ts$/, ".d.ts");
264
267
  const generateMetadataSourceLocker = createMutex();
265
268
  const loggerPrefix = `${packageMetadata.name}-vite`;
266
269
  let logger = packageMetadata.createConsoleLogger(loggerPrefix);
@@ -291,7 +294,28 @@ const screwUp = (options = {}) => {
291
294
  return false;
292
295
  }
293
296
  };
294
- const generateMetadataSourceFile = async () => {
297
+ const ensureMetadataGitignore = async (metadataSourcePath) => {
298
+ const metadataDirectory = path.dirname(metadataSourcePath);
299
+ const gitignorePath = path.join(metadataDirectory, ".gitignore");
300
+ if (fs$1.existsSync(gitignorePath)) {
301
+ return false;
302
+ }
303
+ try {
304
+ await fs.mkdir(metadataDirectory, { recursive: true });
305
+ const metadataFileName = path.basename(metadataSourcePath);
306
+ const gitignoreContent = `# Auto-generated by screw-up plugin
307
+ ${metadataFileName}
308
+ `;
309
+ await fs.writeFile(gitignorePath, gitignoreContent);
310
+ return true;
311
+ } catch (error) {
312
+ logger.warn(
313
+ `Failed to write .gitignore for metadata source: ${gitignorePath}: ${error}`
314
+ );
315
+ return false;
316
+ }
317
+ };
318
+ const generateMetadataSourceFiles = async () => {
295
319
  const result = await packageMetadata.resolvePackageMetadata(
296
320
  projectRoot,
297
321
  fetchGitMetadata,
@@ -301,25 +325,49 @@ const screwUp = (options = {}) => {
301
325
  metadata = result.metadata;
302
326
  banner = generateBanner(metadata, outputKeys);
303
327
  if (outputMetadataFile) {
304
- const metadataSourceContent = generateMetadataFile(
305
- metadata,
306
- outputMetadataKeys
307
- );
328
+ const { content: metadataSourceContent, exportedIdentifiers } = generateMetadataFileContent(metadata, outputMetadataKeys);
308
329
  const metadataSourcePath = path.join(projectRoot, outputMetadataFilePath);
309
- return await writeFileIfChanged(
330
+ const metadataWritten = await writeFileIfChanged(
310
331
  metadataSourcePath,
311
332
  metadataSourceContent,
312
333
  "metadata source file"
313
334
  );
335
+ const metadataTypeContent = generateMetadataTypeFileContent(exportedIdentifiers);
336
+ const metadataTypePath = path.join(
337
+ projectRoot,
338
+ resolvedOutputMetadataTypeFilePath
339
+ );
340
+ const metadataTypeWritten = await writeFileIfChanged(
341
+ metadataTypePath,
342
+ metadataTypeContent,
343
+ "metadata type definition file"
344
+ );
345
+ if (fs$1.existsSync(metadataSourcePath)) {
346
+ const gitignoreWritten = await ensureMetadataGitignore(metadataSourcePath);
347
+ if (gitignoreWritten) {
348
+ logger.info(
349
+ `generateMetadataSourceFile: .gitignore is generated: ${path.join(
350
+ path.dirname(outputMetadataFilePath),
351
+ ".gitignore"
352
+ )}`
353
+ );
354
+ }
355
+ }
356
+ if (metadataTypeWritten) {
357
+ logger.info(
358
+ `generateMetadataSourceFile: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
359
+ );
360
+ }
361
+ return metadataWritten || metadataTypeWritten;
314
362
  }
315
363
  return false;
316
364
  };
317
- const generateMetadataTypeDefinitionFile = async () => {
365
+ const generateMetadataTypeDefinitionFileFromKeys = async (keys) => {
318
366
  if (outputMetadataFile) {
319
- const metadataTypeContent = generateMetadataTypeFile(outputMetadataKeys);
367
+ const metadataTypeContent = generateMetadataTypeFileContent(keys);
320
368
  const metadataTypePath = path.join(
321
369
  projectRoot,
322
- resolvedOutputMetadataFileTypePath
370
+ resolvedOutputMetadataTypeFilePath
323
371
  );
324
372
  return await writeFileIfChanged(
325
373
  metadataTypePath,
@@ -329,17 +377,17 @@ const screwUp = (options = {}) => {
329
377
  }
330
378
  return false;
331
379
  };
332
- const generateDummyMetadataFile = async () => {
380
+ const generateMetadataFileFromKeys = async (keys) => {
333
381
  if (outputMetadataFile) {
334
382
  const metadataSourcePath = path.join(projectRoot, outputMetadataFilePath);
335
383
  if (!fs$1.existsSync(metadataSourcePath)) {
336
384
  const dummyMetadata = {};
337
- outputMetadataKeys.forEach((key) => {
385
+ keys.forEach((key) => {
338
386
  dummyMetadata[key] = "[Require first build]";
339
387
  });
340
- const dummyContent = generateMetadataFile(
388
+ const { content: dummyContent } = generateMetadataFileContent(
341
389
  dummyMetadata,
342
- outputMetadataKeys
390
+ keys
343
391
  );
344
392
  return await writeFileIfChanged(
345
393
  metadataSourcePath,
@@ -359,12 +407,12 @@ const screwUp = (options = {}) => {
359
407
  applyToEnvironment: async (penv) => {
360
408
  logger.info(`${packageMetadata.version}-${packageMetadata.git_commit_hash}: Started.`);
361
409
  projectRoot = penv.config.root;
362
- if (projectRoot && await generateMetadataTypeDefinitionFile()) {
410
+ if (projectRoot && await generateMetadataTypeDefinitionFileFromKeys(outputMetadataKeys)) {
363
411
  logger.info(
364
- `applyToEnvironment: Metadata type definition file is generated: ${resolvedOutputMetadataFileTypePath}`
412
+ `applyToEnvironment: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
365
413
  );
366
414
  }
367
- if (projectRoot && await generateDummyMetadataFile()) {
415
+ if (projectRoot && await generateMetadataFileFromKeys(outputMetadataKeys)) {
368
416
  logger.info(
369
417
  `applyToEnvironment: Dummy metadata source file is generated: ${outputMetadataFilePath}`
370
418
  );
@@ -386,7 +434,7 @@ const screwUp = (options = {}) => {
386
434
  checkWorkingDirectoryStatus,
387
435
  logger
388
436
  );
389
- if (await generateMetadataSourceFile()) {
437
+ if (await generateMetadataSourceFiles()) {
390
438
  logger.info(
391
439
  `configResolved: Metadata source file is generated: ${outputMetadataFilePath}`
392
440
  );
@@ -408,7 +456,7 @@ const screwUp = (options = {}) => {
408
456
  `configureServer: Excluded from watcher: ${outputMetadataFilePath}`
409
457
  );
410
458
  }
411
- if (await generateMetadataSourceFile()) {
459
+ if (await generateMetadataSourceFiles()) {
412
460
  logger.info(
413
461
  `configureServer: Metadata source file is generated: ${outputMetadataFilePath}`
414
462
  );
@@ -423,7 +471,7 @@ const screwUp = (options = {}) => {
423
471
  const l = await generateMetadataSourceLocker.lock();
424
472
  try {
425
473
  logger.debug(`buildStart: Started.`);
426
- if (await generateMetadataSourceFile()) {
474
+ if (await generateMetadataSourceFiles()) {
427
475
  logger.info(
428
476
  `buildStart: Metadata source file is generated: ${outputMetadataFilePath}`
429
477
  );