prepare-package 1.1.5 → 1.1.6

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 (3) hide show
  1. package/dist/index.js +19 -10
  2. package/package.json +1 -1
  3. package/src/index.js +19 -10
package/dist/index.js CHANGED
@@ -12,8 +12,13 @@ module.exports = async function (options) {
12
12
  options.cwd = options.cwd || process.cwd();
13
13
  options.isPostInstall = typeof options.isPostInstall === 'undefined' ? false : options.isPostInstall;
14
14
 
15
+ // Set the paths
16
+ const theirPackageJSONPath = path.resolve(options.cwd, 'package.json');
17
+ const theirPackageJSONExists = jetpack.exists(theirPackageJSONPath);
18
+
19
+ // Get the package.json files
15
20
  const thisPackageJSON = require('../package.json');
16
- const theirPackageJSON = require(path.join(options.cwd, 'package.json'));
21
+ const theirPackageJSON = theirPackageJSONExists ? require(theirPackageJSONPath) : {};
17
22
  const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
18
23
 
19
24
  // const options = {
@@ -58,17 +63,21 @@ module.exports = async function (options) {
58
63
  // Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
59
64
  if (isLivePreparation) {
60
65
  // Replace the main file
61
- jetpack.write(
62
- mainPath,
63
- jetpack.read(mainPath)
64
- .replace(/{version}/igm, theirPackageJSON.version),
65
- );
66
+ if (jetpack.exists(mainPath)) {
67
+ jetpack.write(
68
+ mainPath,
69
+ jetpack.read(mainPath)
70
+ .replace(/{version}/igm, theirPackageJSON.version),
71
+ );
72
+ }
66
73
 
67
74
  // Replace the package.json
68
- jetpack.write(
69
- path.resolve(options.cwd, 'package.json'),
70
- JSON.stringify(theirPackageJSON, null, 2)
71
- );
75
+ if (theirPackageJSONExists) {
76
+ jetpack.write(
77
+ theirPackageJSONPath,
78
+ JSON.stringify(theirPackageJSON, null, 2)
79
+ );
80
+ }
72
81
  }
73
82
 
74
83
  // Handle post install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prepare-package",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Prepare a Node.js package before being published",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -12,8 +12,13 @@ module.exports = async function (options) {
12
12
  options.cwd = options.cwd || process.cwd();
13
13
  options.isPostInstall = typeof options.isPostInstall === 'undefined' ? false : options.isPostInstall;
14
14
 
15
+ // Set the paths
16
+ const theirPackageJSONPath = path.resolve(options.cwd, 'package.json');
17
+ const theirPackageJSONExists = jetpack.exists(theirPackageJSONPath);
18
+
19
+ // Get the package.json files
15
20
  const thisPackageJSON = require('../package.json');
16
- const theirPackageJSON = require(path.join(options.cwd, 'package.json'));
21
+ const theirPackageJSON = theirPackageJSONExists ? require(theirPackageJSONPath) : {};
17
22
  const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
18
23
 
19
24
  // const options = {
@@ -58,17 +63,21 @@ module.exports = async function (options) {
58
63
  // Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
59
64
  if (isLivePreparation) {
60
65
  // Replace the main file
61
- jetpack.write(
62
- mainPath,
63
- jetpack.read(mainPath)
64
- .replace(/{version}/igm, theirPackageJSON.version),
65
- );
66
+ if (jetpack.exists(mainPath)) {
67
+ jetpack.write(
68
+ mainPath,
69
+ jetpack.read(mainPath)
70
+ .replace(/{version}/igm, theirPackageJSON.version),
71
+ );
72
+ }
66
73
 
67
74
  // Replace the package.json
68
- jetpack.write(
69
- path.resolve(options.cwd, 'package.json'),
70
- JSON.stringify(theirPackageJSON, null, 2)
71
- );
75
+ if (theirPackageJSONExists) {
76
+ jetpack.write(
77
+ theirPackageJSONPath,
78
+ JSON.stringify(theirPackageJSON, null, 2)
79
+ );
80
+ }
72
81
  }
73
82
 
74
83
  // Handle post install