prepare-package 1.2.1 → 1.2.3

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.
Files changed (2) hide show
  1. package/dist/index.js +65 -8
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -6,6 +6,40 @@ const logger = require('./logger');
6
6
 
7
7
  // const argv = require('yargs').argv;
8
8
 
9
+ // Helper function to check for local dependencies
10
+ function checkForLocalDependencies(packageJSON) {
11
+ const localDeps = [];
12
+ const depTypes = [
13
+ 'dependencies',
14
+ 'devDependencies',
15
+ 'peerDependencies',
16
+ 'optionalDependencies'
17
+ ];
18
+
19
+ depTypes.forEach(type => {
20
+ if (!packageJSON[type]) {
21
+ return;
22
+ }
23
+
24
+ Object.entries(packageJSON[type]).forEach(([name, version]) => {
25
+ // Check for file: protocol or relative/absolute paths
26
+ if (version.startsWith('file:')
27
+ || version.startsWith('../')
28
+ || version.startsWith('./')
29
+ || version.startsWith('/')
30
+ || version.startsWith('~')) {
31
+ localDeps.push({
32
+ type,
33
+ name,
34
+ value: version
35
+ });
36
+ }
37
+ });
38
+ });
39
+
40
+ return localDeps;
41
+ }
42
+
9
43
  module.exports = async function (options) {
10
44
  // Set the options
11
45
  options = options || {};
@@ -14,6 +48,12 @@ module.exports = async function (options) {
14
48
  options.isPostInstall = typeof options.isPostInstall === 'undefined' ? false : options.isPostInstall;
15
49
  options.singleFile = options.singleFile || null; // For watch mode - single file to process
16
50
 
51
+ // Detect if running via npm publish
52
+ const isPublishing = process.env.npm_lifecycle_event === 'prepublishOnly'
53
+ || process.env.npm_lifecycle_event === 'prepublish'
54
+ || process.env.npm_lifecycle_event === 'publish';
55
+ const isManualPrepare = process.env.npm_lifecycle_event === 'prepare';
56
+
17
57
  // Set the paths
18
58
  const theirPackageJSONPath = path.resolve(options.cwd, 'package.json');
19
59
  const theirPackageJSONExists = jetpack.exists(theirPackageJSONPath);
@@ -23,6 +63,19 @@ module.exports = async function (options) {
23
63
  const theirPackageJSON = theirPackageJSONExists ? require(theirPackageJSONPath) : {};
24
64
  const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
25
65
 
66
+ // Check for local dependencies when publishing
67
+ if (isPublishing) {
68
+ const hasLocalDeps = checkForLocalDependencies(theirPackageJSON);
69
+ if (hasLocalDeps.length > 0) {
70
+ logger.error('Cannot publish with local dependencies!');
71
+ logger.error('The following dependencies use local file references:');
72
+ hasLocalDeps.forEach(dep => {
73
+ logger.error(` - ${dep.type}: ${dep.name} -> ${dep.value}`);
74
+ });
75
+ throw new Error('Publishing blocked: Remove local file dependencies before publishing to npm');
76
+ }
77
+ }
78
+
26
79
  // const options = {
27
80
  // purge: argv['--purge'] || argv['-p'],
28
81
  // };
@@ -48,13 +101,17 @@ module.exports = async function (options) {
48
101
  // console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));
49
102
  // console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
50
103
  // console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
51
- logger.log(`Starting...`);
52
- logger.log({
53
- purge: options.purge,
54
- input: theirPackageJSON.preparePackage.input,
55
- output: theirPackageJSON.preparePackage.output,
56
- main: theirPackageJSON.main,
57
- });
104
+ if (!options.singleFile) {
105
+ logger.log(`Starting...${isPublishing ? ' (via npm publish)' : ''}`);
106
+ logger.log({
107
+ purge: options.purge,
108
+ input: theirPackageJSON.preparePackage.input,
109
+ output: theirPackageJSON.preparePackage.output,
110
+ main: theirPackageJSON.main,
111
+ isPublishing: isPublishing,
112
+ lifecycle: process.env.npm_lifecycle_event,
113
+ });
114
+ }
58
115
 
59
116
  // Set the paths relative to the cwd
60
117
  const mainPath = path.resolve(options.cwd, theirPackageJSON.main);
@@ -70,7 +127,7 @@ module.exports = async function (options) {
70
127
  if (options.singleFile) {
71
128
  const relativePath = path.relative(inputPath, options.singleFile);
72
129
  const destPath = path.join(outputPath, relativePath);
73
-
130
+
74
131
  // Copy single file
75
132
  if (jetpack.exists(options.singleFile)) {
76
133
  jetpack.copy(options.singleFile, destPath, { overwrite: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prepare-package",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Prepare a Node.js package before being published",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -40,9 +40,9 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "chalk": "^4.1.2",
43
- "chokidar": "^3.5.3",
44
- "fs-jetpack": "^4.3.1",
45
- "wonderful-fetch": "^1.3.2"
43
+ "chokidar": "^4.0.3",
44
+ "fs-jetpack": "^5.1.0",
45
+ "wonderful-fetch": "^1.3.3"
46
46
  },
47
47
  "devDependencies": {
48
48
  "mocha": "^8.4.0"