screw-up 1.7.0 → 1.9.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.
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.7.0
3
+ * version: 1.9.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: 0865d5a2d4d1e89be8dae4b6abeba1393a767707
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
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.7.0
3
+ * version: 1.9.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: 0865d5a2d4d1e89be8dae4b6abeba1393a767707
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
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.7.0
3
+ * version: 1.9.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: 0865d5a2d4d1e89be8dae4b6abeba1393a767707
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  import { Logger } from './internal';
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.7.0
3
+ * version: 1.9.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: 0865d5a2d4d1e89be8dae4b6abeba1393a767707
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
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.7.0
3
+ * version: 1.9.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: 0865d5a2d4d1e89be8dae4b6abeba1393a767707
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  export declare const name = "screw-up";
12
- export declare const version = "1.7.0";
12
+ export declare const version = "1.9.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 = "0865d5a2d4d1e89be8dae4b6abeba1393a767707";
17
+ export declare const git_commit_hash = "55707baccdf2d4d14a40310e88ad41531c1a8ff0";
18
18
  //# sourceMappingURL=packageMetadata.d.ts.map
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.7.0
3
+ * version: 1.9.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: 0865d5a2d4d1e89be8dae4b6abeba1393a767707
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
9
9
  */
10
10
 
11
11
  import { TagInfo, Version } from './analyzer';
package/dist/index.cjs CHANGED
@@ -1,25 +1,25 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.7.0
3
+ * version: 1.9.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: 0865d5a2d4d1e89be8dae4b6abeba1393a767707
8
+ * git.commit.hash: 55707baccdf2d4d14a40310e88ad41531c1a8ff0
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-B3Z9TVh6.cjs");
14
+ const packageMetadata = require("./packageMetadata-BA-kOu7C.cjs");
15
15
  /*!
16
16
  * name: async-primitives
17
- * version: 1.0.0
17
+ * version: 1.2.0
18
18
  * description: A collection of primitive functions for asynchronous operations
19
19
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
20
20
  * license: MIT
21
21
  * repository.url: https://github.com/kekyo/async-primitives.git
22
- * git.commit.hash: 87c2c54e1ee681110dd8e9e0466ee12c15f5557c
22
+ * git.commit.hash: 3b7bffeaa8ae47aea6e8b0ef0f70e265a6d9ab08
23
23
  */
24
24
  const __NOOP_HANDLER = () => {
25
25
  };
@@ -166,8 +166,11 @@ const createMutex = (maxConsecutiveCalls = 20) => {
166
166
  });
167
167
  }
168
168
  };
169
- return {
169
+ const result = {
170
170
  lock,
171
+ waiter: {
172
+ wait: lock
173
+ },
171
174
  get isLocked() {
172
175
  return isLocked;
173
176
  },
@@ -175,6 +178,7 @@ const createMutex = (maxConsecutiveCalls = 20) => {
175
178
  return queue.length;
176
179
  }
177
180
  };
181
+ return result;
178
182
  };
179
183
  const generateBanner = (metadata, outputKeys) => {
180
184
  const parts = [];
@@ -199,8 +203,9 @@ const insertBannerHeader = (content, banner) => {
199
203
  const sanitizeKey = (key) => {
200
204
  return key.replace(/[^a-zA-Z0-9_]/g, "_").replace(/^(\d)/, "_$1");
201
205
  };
202
- const generateMetadataFile = (metadata, outputKeys) => {
206
+ const generateMetadataFileContent = (metadata, outputKeys) => {
203
207
  const lines = [];
208
+ const exportedIdentifiers = [];
204
209
  lines.push("// This file is auto-generated by screw-up plugin");
205
210
  lines.push("// Do not edit manually");
206
211
  lines.push("");
@@ -210,12 +215,13 @@ const generateMetadataFile = (metadata, outputKeys) => {
210
215
  const sanitizedKey = sanitizeKey(key);
211
216
  const escapedValue = JSON.stringify(value);
212
217
  lines.push(`export const ${sanitizedKey} = ${escapedValue};`);
218
+ exportedIdentifiers.push(sanitizedKey);
213
219
  }
214
220
  }
215
221
  lines.push("");
216
- return lines.join("\n");
222
+ return { content: lines.join("\n"), exportedIdentifiers };
217
223
  };
218
- const generateMetadataTypeFile = (outputKeys) => {
224
+ const generateMetadataTypeFileContent = (outputKeys) => {
219
225
  const lines = [];
220
226
  lines.push("// This file is auto-generated by screw-up plugin");
221
227
  lines.push("// Do not edit manually");
@@ -256,7 +262,7 @@ const screwUp = (options = {}) => {
256
262
  insertMetadataBanner = true
257
263
  } = options;
258
264
  const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
259
- const resolvedOutputMetadataFileTypePath = outputMetadataFileTypePath || outputMetadataFilePath.replace(/\.ts$/, ".d.ts");
265
+ const resolvedOutputMetadataTypeFilePath = outputMetadataFileTypePath || outputMetadataFilePath.replace(/\.ts$/, ".d.ts");
260
266
  const generateMetadataSourceLocker = createMutex();
261
267
  const loggerPrefix = `${packageMetadata.name}-vite`;
262
268
  let logger = packageMetadata.createConsoleLogger(loggerPrefix);
@@ -287,7 +293,28 @@ const screwUp = (options = {}) => {
287
293
  return false;
288
294
  }
289
295
  };
290
- const generateMetadataSourceFile = async () => {
296
+ const ensureMetadataGitignore = async (metadataSourcePath) => {
297
+ const metadataDirectory = path.dirname(metadataSourcePath);
298
+ const gitignorePath = path.join(metadataDirectory, ".gitignore");
299
+ if (fs$1.existsSync(gitignorePath)) {
300
+ return false;
301
+ }
302
+ try {
303
+ await fs.mkdir(metadataDirectory, { recursive: true });
304
+ const metadataFileName = path.basename(metadataSourcePath);
305
+ const gitignoreContent = `# Auto-generated by screw-up plugin
306
+ ${metadataFileName}
307
+ `;
308
+ await fs.writeFile(gitignorePath, gitignoreContent);
309
+ return true;
310
+ } catch (error) {
311
+ logger.warn(
312
+ `Failed to write .gitignore for metadata source: ${gitignorePath}: ${error}`
313
+ );
314
+ return false;
315
+ }
316
+ };
317
+ const generateMetadataSourceFiles = async () => {
291
318
  const result = await packageMetadata.resolvePackageMetadata(
292
319
  projectRoot,
293
320
  fetchGitMetadata,
@@ -297,25 +324,49 @@ const screwUp = (options = {}) => {
297
324
  metadata = result.metadata;
298
325
  banner = generateBanner(metadata, outputKeys);
299
326
  if (outputMetadataFile) {
300
- const metadataSourceContent = generateMetadataFile(
301
- metadata,
302
- outputMetadataKeys
303
- );
327
+ const { content: metadataSourceContent, exportedIdentifiers } = generateMetadataFileContent(metadata, outputMetadataKeys);
304
328
  const metadataSourcePath = path.join(projectRoot, outputMetadataFilePath);
305
- return await writeFileIfChanged(
329
+ const metadataWritten = await writeFileIfChanged(
306
330
  metadataSourcePath,
307
331
  metadataSourceContent,
308
332
  "metadata source file"
309
333
  );
334
+ const metadataTypeContent = generateMetadataTypeFileContent(exportedIdentifiers);
335
+ const metadataTypePath = path.join(
336
+ projectRoot,
337
+ resolvedOutputMetadataTypeFilePath
338
+ );
339
+ const metadataTypeWritten = await writeFileIfChanged(
340
+ metadataTypePath,
341
+ metadataTypeContent,
342
+ "metadata type definition file"
343
+ );
344
+ if (fs$1.existsSync(metadataSourcePath)) {
345
+ const gitignoreWritten = await ensureMetadataGitignore(metadataSourcePath);
346
+ if (gitignoreWritten) {
347
+ logger.info(
348
+ `generateMetadataSourceFile: .gitignore is generated: ${path.join(
349
+ path.dirname(outputMetadataFilePath),
350
+ ".gitignore"
351
+ )}`
352
+ );
353
+ }
354
+ }
355
+ if (metadataTypeWritten) {
356
+ logger.info(
357
+ `generateMetadataSourceFile: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
358
+ );
359
+ }
360
+ return metadataWritten || metadataTypeWritten;
310
361
  }
311
362
  return false;
312
363
  };
313
- const generateMetadataTypeDefinitionFile = async () => {
364
+ const generateMetadataTypeDefinitionFileFromKeys = async (keys) => {
314
365
  if (outputMetadataFile) {
315
- const metadataTypeContent = generateMetadataTypeFile(outputMetadataKeys);
366
+ const metadataTypeContent = generateMetadataTypeFileContent(keys);
316
367
  const metadataTypePath = path.join(
317
368
  projectRoot,
318
- resolvedOutputMetadataFileTypePath
369
+ resolvedOutputMetadataTypeFilePath
319
370
  );
320
371
  return await writeFileIfChanged(
321
372
  metadataTypePath,
@@ -325,17 +376,17 @@ const screwUp = (options = {}) => {
325
376
  }
326
377
  return false;
327
378
  };
328
- const generateDummyMetadataFile = async () => {
379
+ const generateMetadataFileFromKeys = async (keys) => {
329
380
  if (outputMetadataFile) {
330
381
  const metadataSourcePath = path.join(projectRoot, outputMetadataFilePath);
331
382
  if (!fs$1.existsSync(metadataSourcePath)) {
332
383
  const dummyMetadata = {};
333
- outputMetadataKeys.forEach((key) => {
384
+ keys.forEach((key) => {
334
385
  dummyMetadata[key] = "[Require first build]";
335
386
  });
336
- const dummyContent = generateMetadataFile(
387
+ const { content: dummyContent } = generateMetadataFileContent(
337
388
  dummyMetadata,
338
- outputMetadataKeys
389
+ keys
339
390
  );
340
391
  return await writeFileIfChanged(
341
392
  metadataSourcePath,
@@ -355,12 +406,12 @@ const screwUp = (options = {}) => {
355
406
  applyToEnvironment: async (penv) => {
356
407
  logger.info(`${packageMetadata.version}-${packageMetadata.git_commit_hash}: Started.`);
357
408
  projectRoot = penv.config.root;
358
- if (projectRoot && await generateMetadataTypeDefinitionFile()) {
409
+ if (projectRoot && await generateMetadataTypeDefinitionFileFromKeys(outputMetadataKeys)) {
359
410
  logger.info(
360
- `applyToEnvironment: Metadata type definition file is generated: ${resolvedOutputMetadataFileTypePath}`
411
+ `applyToEnvironment: Metadata type definition file is generated: ${resolvedOutputMetadataTypeFilePath}`
361
412
  );
362
413
  }
363
- if (projectRoot && await generateDummyMetadataFile()) {
414
+ if (projectRoot && await generateMetadataFileFromKeys(outputMetadataKeys)) {
364
415
  logger.info(
365
416
  `applyToEnvironment: Dummy metadata source file is generated: ${outputMetadataFilePath}`
366
417
  );
@@ -382,7 +433,7 @@ const screwUp = (options = {}) => {
382
433
  checkWorkingDirectoryStatus,
383
434
  logger
384
435
  );
385
- if (await generateMetadataSourceFile()) {
436
+ if (await generateMetadataSourceFiles()) {
386
437
  logger.info(
387
438
  `configResolved: Metadata source file is generated: ${outputMetadataFilePath}`
388
439
  );
@@ -404,7 +455,7 @@ const screwUp = (options = {}) => {
404
455
  `configureServer: Excluded from watcher: ${outputMetadataFilePath}`
405
456
  );
406
457
  }
407
- if (await generateMetadataSourceFile()) {
458
+ if (await generateMetadataSourceFiles()) {
408
459
  logger.info(
409
460
  `configureServer: Metadata source file is generated: ${outputMetadataFilePath}`
410
461
  );
@@ -419,7 +470,7 @@ const screwUp = (options = {}) => {
419
470
  const l = await generateMetadataSourceLocker.lock();
420
471
  try {
421
472
  logger.debug(`buildStart: Started.`);
422
- if (await generateMetadataSourceFile()) {
473
+ if (await generateMetadataSourceFiles()) {
423
474
  logger.info(
424
475
  `buildStart: Metadata source file is generated: ${outputMetadataFilePath}`
425
476
  );