prepare-package 1.2.2 → 1.2.4

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 +60 -1
  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,13 @@ 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
+ // When npm publish runs, it sets npm_command to 'publish' even though lifecycle_event is 'prepare'
53
+ const isPublishing = process.env.npm_command === 'publish'
54
+ || process.env.npm_lifecycle_event === 'prepublishOnly'
55
+ || process.env.npm_lifecycle_event === 'prepublish';
56
+ const isManualPrepare = process.env.npm_lifecycle_event === 'prepare' && !isPublishing;
57
+
17
58
  // Set the paths
18
59
  const theirPackageJSONPath = path.resolve(options.cwd, 'package.json');
19
60
  const theirPackageJSONExists = jetpack.exists(theirPackageJSONPath);
@@ -23,6 +64,20 @@ module.exports = async function (options) {
23
64
  const theirPackageJSON = theirPackageJSONExists ? require(theirPackageJSONPath) : {};
24
65
  const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
25
66
 
67
+
68
+ // Check for local dependencies when publishing
69
+ if (isPublishing) {
70
+ const hasLocalDeps = checkForLocalDependencies(theirPackageJSON);
71
+ if (hasLocalDeps.length > 0) {
72
+ logger.error('Cannot publish with local dependencies!');
73
+ logger.error('The following dependencies use local file references:');
74
+ hasLocalDeps.forEach(dep => {
75
+ logger.error(` - ${dep.type}: ${dep.name} -> ${dep.value}`);
76
+ });
77
+ throw new Error('Publishing blocked: Remove local file dependencies before publishing to npm');
78
+ }
79
+ }
80
+
26
81
  // const options = {
27
82
  // purge: argv['--purge'] || argv['-p'],
28
83
  // };
@@ -49,12 +104,16 @@ module.exports = async function (options) {
49
104
  // console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
50
105
  // console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
51
106
  if (!options.singleFile) {
52
- logger.log(`Starting...`);
107
+ logger.log(`Starting...${isPublishing ? ' (via npm publish)' : ''}`);
53
108
  logger.log({
54
109
  purge: options.purge,
55
110
  input: theirPackageJSON.preparePackage.input,
56
111
  output: theirPackageJSON.preparePackage.output,
57
112
  main: theirPackageJSON.main,
113
+
114
+ // lifecycle: process.env.npm_lifecycle_event,
115
+ // command: process.env.npm_command,
116
+ isPublishing: isPublishing,
58
117
  });
59
118
  }
60
119
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prepare-package",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
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"