prepare-package 1.2.0 → 1.2.1

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/dist/index.js CHANGED
@@ -12,6 +12,7 @@ module.exports = async function (options) {
12
12
  options.purge = typeof options.purge === 'undefined' ? true : options.purge;
13
13
  options.cwd = options.cwd || process.cwd();
14
14
  options.isPostInstall = typeof options.isPostInstall === 'undefined' ? false : options.isPostInstall;
15
+ options.singleFile = options.singleFile || null; // For watch mode - single file to process
15
16
 
16
17
  // Set the paths
17
18
  const theirPackageJSONPath = path.resolve(options.cwd, 'package.json');
@@ -65,33 +66,58 @@ module.exports = async function (options) {
65
66
  const outputPathExists = jetpack.exists(outputPath);
66
67
  const inputPathExists = jetpack.exists(inputPath);
67
68
 
68
- // Remove the output folder if it exists (input must exist too)
69
- if (outputPathExists && inputPathExists) {
70
- jetpack.remove(outputPath);
71
- }
69
+ // Handle single file mode (for watch)
70
+ if (options.singleFile) {
71
+ const relativePath = path.relative(inputPath, options.singleFile);
72
+ const destPath = path.join(outputPath, relativePath);
73
+
74
+ // Copy single file
75
+ if (jetpack.exists(options.singleFile)) {
76
+ jetpack.copy(options.singleFile, destPath, { overwrite: true });
77
+ logger.log(`Updated: ${relativePath}`);
78
+ }
79
+ } else {
80
+ // Normal mode - full copy
81
+ // Remove the output folder if it exists (input must exist too)
82
+ if (outputPathExists && inputPathExists) {
83
+ jetpack.remove(outputPath);
84
+ }
72
85
 
73
- // Copy the input folder to the output folder if it exists
74
- if (inputPathExists) {
75
- jetpack.copy(inputPath, outputPath);
86
+ // Copy the input folder to the output folder if it exists
87
+ if (inputPathExists) {
88
+ jetpack.copy(inputPath, outputPath);
89
+ }
76
90
  }
77
91
 
78
92
  // Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
79
93
  if (isLivePreparation) {
80
- // Replace the main file
81
- if (mainPathExists) {
82
- jetpack.write(
83
- mainPath,
84
- jetpack.read(mainPath)
85
- .replace(/{version}/igm, theirPackageJSON.version),
86
- );
87
- }
88
-
89
- // Replace the package.json
90
- if (theirPackageJSONExists) {
91
- jetpack.write(
92
- theirPackageJSONPath,
93
- `${JSON.stringify(theirPackageJSON, null, 2)}\n`
94
- );
94
+ // In single file mode, only process if it's the main file
95
+ if (options.singleFile) {
96
+ const destPath = path.join(outputPath, path.relative(inputPath, options.singleFile));
97
+ if (destPath === mainPath && jetpack.exists(destPath)) {
98
+ jetpack.write(
99
+ destPath,
100
+ jetpack.read(destPath).replace(/{version}/igm, theirPackageJSON.version)
101
+ );
102
+ }
103
+ } else {
104
+ // Normal mode - process main file and package.json
105
+ // Replace the main file
106
+ if (mainPathExists) {
107
+ jetpack.write(
108
+ mainPath,
109
+ jetpack.read(mainPath)
110
+ .replace(/{version}/igm, theirPackageJSON.version),
111
+ );
112
+ }
113
+
114
+ // Replace the package.json
115
+ if (theirPackageJSONExists) {
116
+ jetpack.write(
117
+ theirPackageJSONPath,
118
+ `${JSON.stringify(theirPackageJSON, null, 2)}\n`
119
+ );
120
+ }
95
121
  }
96
122
  }
97
123
 
package/dist/watch.js CHANGED
@@ -16,8 +16,6 @@ module.exports = async function watch() {
16
16
  packageJSON.preparePackage = packageJSON.preparePackage || {};
17
17
  const inputPath = path.resolve(cwd, packageJSON.preparePackage.input || './src');
18
18
  const outputPath = path.resolve(cwd, packageJSON.preparePackage.output || './dist');
19
- const mainPath = path.resolve(cwd, packageJSON.main || './dist/index.js');
20
- const isLivePreparation = packageJSON.name !== 'prepare-package';
21
19
 
22
20
  // Run initial prepare (full copy)
23
21
  logger.log('Running initial prepare...');
@@ -37,7 +35,7 @@ module.exports = async function watch() {
37
35
  });
38
36
 
39
37
  // Helper function to process a single file
40
- const processSingleFile = (filePath, eventType) => {
38
+ const processSingleFile = async (filePath, eventType) => {
41
39
  const relativePath = path.relative(inputPath, filePath);
42
40
  const destPath = path.join(outputPath, relativePath);
43
41
 
@@ -53,18 +51,11 @@ module.exports = async function watch() {
53
51
  jetpack.dir(destPath);
54
52
  logger.log(`Created dir: ${relativePath}`);
55
53
  } else if (eventType === 'add' || eventType === 'change') {
56
- // Copy the file to output
57
- jetpack.copy(filePath, destPath, { overwrite: true });
58
-
59
- // Apply version replacement if it's the main file
60
- if (isLivePreparation && destPath === mainPath) {
61
- jetpack.write(
62
- destPath,
63
- jetpack.read(destPath).replace(/{version}/igm, packageJSON.version)
64
- );
65
- }
66
-
67
- logger.log(`Updated: ${relativePath}`);
54
+ // Use the main prepare function with singleFile option
55
+ await prepare({
56
+ purge: false,
57
+ singleFile: filePath
58
+ });
68
59
  }
69
60
  } catch (error) {
70
61
  logger.error(`Error processing ${relativePath}: ${error.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prepare-package",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Prepare a Node.js package before being published",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -47,4 +47,4 @@
47
47
  "devDependencies": {
48
48
  "mocha": "^8.4.0"
49
49
  }
50
- }
50
+ }