just-scripts 2.4.1 → 2.5.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.
Files changed (64) hide show
  1. package/CHANGELOG.json +52 -1
  2. package/CHANGELOG.md +19 -2
  3. package/lib/index.d.ts +1 -1
  4. package/lib/index.d.ts.map +1 -1
  5. package/lib/index.js +4 -3
  6. package/lib/index.js.map +1 -1
  7. package/lib/interfaces/PackageJson.d.ts +16 -0
  8. package/lib/interfaces/PackageJson.d.ts.map +1 -0
  9. package/lib/interfaces/PackageJson.js +3 -0
  10. package/lib/interfaces/PackageJson.js.map +1 -0
  11. package/lib/tasks/eslintTask.d.ts +4 -0
  12. package/lib/tasks/eslintTask.d.ts.map +1 -1
  13. package/lib/tasks/eslintTask.js +4 -3
  14. package/lib/tasks/eslintTask.js.map +1 -1
  15. package/lib/tasks/jestTask.js +4 -4
  16. package/lib/tasks/jestTask.js.map +1 -1
  17. package/lib/tasks/nodeExecTask.js +2 -2
  18. package/lib/tasks/nodeExecTask.js.map +1 -1
  19. package/lib/tasks/prettierTask.js +2 -2
  20. package/lib/tasks/prettierTask.js.map +1 -1
  21. package/lib/tasks/tscTask.js +5 -5
  22. package/lib/tasks/tscTask.js.map +1 -1
  23. package/lib/tasks/tslintTask.js +3 -3
  24. package/lib/tasks/tslintTask.js.map +1 -1
  25. package/lib/tasks/webpackCliTask.js +2 -2
  26. package/lib/tasks/webpackCliTask.js.map +1 -1
  27. package/lib/tasks/webpackDevServerTask.js +3 -3
  28. package/lib/tasks/webpackDevServerTask.js.map +1 -1
  29. package/lib/utils/exec.d.ts +48 -0
  30. package/lib/utils/exec.d.ts.map +1 -0
  31. package/lib/utils/exec.js +115 -0
  32. package/lib/utils/exec.js.map +1 -0
  33. package/lib/utils/index.d.ts +5 -0
  34. package/lib/utils/index.d.ts.map +1 -0
  35. package/lib/utils/index.js +19 -0
  36. package/lib/utils/index.js.map +1 -0
  37. package/lib/utils/mergePackageJson.d.ts +20 -0
  38. package/lib/utils/mergePackageJson.d.ts.map +1 -0
  39. package/lib/utils/mergePackageJson.js +61 -0
  40. package/lib/utils/mergePackageJson.js.map +1 -0
  41. package/lib/utils/paths.d.ts +13 -0
  42. package/lib/utils/paths.d.ts.map +1 -0
  43. package/lib/utils/paths.js +26 -0
  44. package/lib/utils/paths.js.map +1 -0
  45. package/lib/utils/readPackageJson.d.ts +8 -0
  46. package/lib/utils/readPackageJson.d.ts.map +1 -0
  47. package/lib/utils/readPackageJson.js +19 -0
  48. package/lib/utils/readPackageJson.js.map +1 -0
  49. package/package.json +2 -3
  50. package/src/index.ts +1 -1
  51. package/src/interfaces/PackageJson.ts +16 -0
  52. package/src/tasks/eslintTask.ts +6 -1
  53. package/src/tasks/jestTask.ts +2 -2
  54. package/src/tasks/nodeExecTask.ts +1 -1
  55. package/src/tasks/prettierTask.ts +1 -1
  56. package/src/tasks/tscTask.ts +1 -1
  57. package/src/tasks/tslintTask.ts +1 -1
  58. package/src/tasks/webpackCliTask.ts +1 -1
  59. package/src/tasks/webpackDevServerTask.ts +1 -1
  60. package/src/utils/exec.ts +126 -0
  61. package/src/utils/index.ts +4 -0
  62. package/src/utils/mergePackageJson.ts +64 -0
  63. package/src/utils/paths.ts +26 -0
  64. package/src/utils/readPackageJson.ts +16 -0
@@ -0,0 +1,64 @@
1
+ import { PackageJson } from '../interfaces/PackageJson';
2
+ import semver = require('semver');
3
+
4
+ /**
5
+ * Merges an incoming package.json with an original semantically. It can only handle merging
6
+ * dependencies and devDependencies for ranges that look like "^x.y.z" or "~x.y.z" or "x.y.z".
7
+ *
8
+ * @param original Original package.json contents.
9
+ * @param incoming Incoming package.json contents.
10
+ * @returns Returns a new package.json object if any changes were needed, or returns `original`
11
+ * if not. (You can tell if changes were made by checking the object identity.)
12
+ */
13
+ export function mergePackageJson(original: PackageJson, incoming: PackageJson): PackageJson {
14
+ if (!original.just) {
15
+ return original;
16
+ }
17
+
18
+ // deep copy the deps and devDeps
19
+ const newPackageJson: PackageJson = {
20
+ ...original,
21
+ dependencies: { ...(original.dependencies || {}) },
22
+ devDependencies: { ...(original.devDependencies || {}) },
23
+ };
24
+
25
+ const depTypes = ['dependencies', 'devDependencies'];
26
+ let packageJsonModified = false;
27
+ depTypes.forEach(depType => {
28
+ const incomingDeps = incoming[depType] || {};
29
+ const originalDeps = original[depType] || {};
30
+
31
+ Object.keys(incomingDeps).forEach(dep => {
32
+ // TODO: should this handle deleting deps that exist in originalDeps but not incomingDeps?
33
+ if (_shouldUpdateDep(originalDeps[dep], incomingDeps[dep])) {
34
+ newPackageJson[depType][dep] = incomingDeps[dep];
35
+ packageJsonModified = true;
36
+ }
37
+ });
38
+ });
39
+
40
+ return packageJsonModified ? newPackageJson : original;
41
+ }
42
+
43
+ /**
44
+ * Exported for testing only. Determines whether a dep should be updated.
45
+ * Returns false if either version includes semver elements we don't understand
46
+ * (any characters besides number and ~ ^).
47
+ * @param originalVersion The original dep version (default 0.0.0)
48
+ * @param incomingVersion The incoming dep version
49
+ */
50
+ export function _shouldUpdateDep(originalVersion: string | undefined, incomingVersion: string): boolean {
51
+ const strippedOriginalVersion = (originalVersion || '0.0.0').replace(/^[~^]/, '');
52
+ const strippedIncomingVersion = incomingVersion.replace(/^[~^]/, '');
53
+
54
+ // semver.valid only returns true for a valid SINGLE version, not any type of range
55
+ if (!semver.valid(strippedOriginalVersion) || !semver.valid(strippedIncomingVersion)) {
56
+ // The original and/or incoming versions (with ~ and ^ removed) can't be understood as a single
57
+ // semver version. They might be valid ranges of some other form (like with x or ||), but we
58
+ // don't currently handle those. Do nothing.
59
+ return false;
60
+ }
61
+
62
+ // Modify the version if the range is comparable and is greater
63
+ return semver.gt(strippedIncomingVersion, strippedOriginalVersion);
64
+ }
@@ -0,0 +1,26 @@
1
+ import * as path from 'path';
2
+ import * as os from 'os';
3
+
4
+ let projectPath = '';
5
+
6
+ export const paths = {
7
+ /**
8
+ * Location where the generated project will go. Defaults to `process.cwd()`.
9
+ */
10
+ get projectPath(): string {
11
+ return projectPath || process.cwd();
12
+ },
13
+
14
+ set projectPath(value: string) {
15
+ projectPath = value;
16
+ },
17
+
18
+ /**
19
+ * Gets a directory path under `${os.tmpdir()}/just-stack` for temporarily storing files.
20
+ * @param segments Names of extra directory segments to include.
21
+ * @returns The directory path.
22
+ */
23
+ tempPath(...segments: string[]): string {
24
+ return path.resolve(os.tmpdir(), 'just-stack', ...segments);
25
+ },
26
+ };
@@ -0,0 +1,16 @@
1
+ import * as path from 'path';
2
+ import { PackageJson } from '../interfaces/PackageJson';
3
+ import fse = require('fs-extra');
4
+
5
+ /**
6
+ * Reads and parses the package.json file from the given folder.
7
+ * @param folderPath The folder path to look for a package.json in.
8
+ * @returns The parsed file contents, or undefined if the file doesn't exist.
9
+ */
10
+ export function readPackageJson(folderPath: string): PackageJson | undefined {
11
+ const packageJsonPath = path.join(folderPath, 'package.json');
12
+ if (fse.existsSync(packageJsonPath)) {
13
+ return fse.readJsonSync(packageJsonPath, { throws: false }) || undefined;
14
+ }
15
+ return undefined;
16
+ }