eject 1.0.0 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.0.1](https://github.com/snake-py/eject/compare/v1.0.0...v1.0.1) (2024-11-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * use `link:` protocol instead of `file:` ([40cbab3](https://github.com/snake-py/eject/commit/40cbab318c94ebf9953e90ffa4f9b739e0282f80))
7
+
8
+
9
+
1
10
  # 1.0.0 (2024-11-15)
2
11
 
3
12
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Eject
2
2
 
3
- This package is written to help you to eject your project from the current repository. It will copy all the files and folders to `ejected` folder and remove it from node_modules.
3
+ This package is written to eject dependencies from your project. It will copy all the files and folders to an `ejected` folder and remove it from node_modules. It will automatically update the package.json file an link the dependencies to the ejected folder.
4
4
 
5
5
 
6
6
  ## Usage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eject",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "This package helps you to eject dependencies from node_modules easily",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/command.ts CHANGED
@@ -7,7 +7,12 @@ import {
7
7
  isGitInstalled,
8
8
  } from './git.js';
9
9
  import { errorLog, infoLog, warnLog } from './log.js';
10
- import { copyDependency, install, updatePackageJson } from './system.js';
10
+ import {
11
+ copyDependency,
12
+ detectPackageManager,
13
+ updatePackageJson,
14
+ } from './system.js';
15
+ import { execSync } from 'child_process';
11
16
 
12
17
  export function eject(
13
18
  dependencies: string[],
@@ -52,11 +57,12 @@ export function eject(
52
57
  }
53
58
  updatePackageJson(successFullEjections);
54
59
  commitEjection(config.COMMIT_MESSAGE);
55
- console.log(
56
- `📦 Installing dependencies (you can skip this e.g. with ${chalk.bold('Ctrl + C')})`,
57
- );
58
- install();
59
- console.log('✅ Install done');
60
+ const { packageManager, lockFile } = detectPackageManager();
61
+ const installCmd = `${packageManager} install`;
62
+ const installLog = chalk.bold(installCmd);
63
+ console.log(`📦 Running ${installLog} to update ${chalk.bold(lockFile)}`);
64
+ execSync(installCmd, { stdio: 'inherit' });
65
+ console.log(`✅ ${installLog} done`);
60
66
  amendCommit();
61
67
  console.log(
62
68
  '➡️ Run',
package/src/system.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { resolve } from 'path';
2
2
  import fs from 'fs';
3
- import { execSync } from 'child_process';
3
+ import assert from 'assert';
4
4
 
5
5
  export function updatePackageJson(successFullEjections: string[]) {
6
6
  const packageJson = JSON.parse(
@@ -30,7 +30,7 @@ function setPathAsVersion(
30
30
  if (!successFullEjections.includes(key)) {
31
31
  updatedDependencies[key] = dependencies[key] as string;
32
32
  } else {
33
- updatedDependencies[key] = `file:./ejected/${key}`;
33
+ updatedDependencies[key] = `link:./ejected/${key}`;
34
34
  }
35
35
  }
36
36
  return updatedDependencies;
@@ -56,12 +56,10 @@ export function copyDependency(dependency: string) {
56
56
  });
57
57
  }
58
58
 
59
- export function install() {
60
- const packageManager = detectPackageManager();
61
- execSync(`${packageManager} install`, { stdio: 'inherit' });
62
- }
63
-
64
- const detectPackageManager = (currentDir: string = './', depth: number = 0) => {
59
+ export function detectPackageManager(
60
+ currentDir: string = './',
61
+ depth: number = 0,
62
+ ) {
65
63
  if (depth > 20) {
66
64
  throw new Error('No lock file found');
67
65
  }
@@ -85,17 +83,18 @@ const detectPackageManager = (currentDir: string = './', depth: number = 0) => {
85
83
  if (foundLockFiles.length > 1) {
86
84
  throw new Error('Multiple lock files found');
87
85
  }
88
- const foundLock = foundLockFiles[0] as string;
89
86
 
90
- if (foundLock === 'yarn.lock') {
91
- return 'yarn';
92
- } else if (foundLock === 'package-lock.json') {
93
- return 'npm';
94
- } else if (foundLock === 'pnpm-lock.yaml') {
95
- return 'pnpm';
96
- } else if (foundLock === 'bun.lock') {
97
- return 'bun';
87
+ const lockFile = foundLockFiles[0] as string;
88
+ let packageManager: string | undefined;
89
+ if (lockFile === 'yarn.lock') {
90
+ packageManager = 'yarn';
91
+ } else if (lockFile === 'package-lock.json') {
92
+ packageManager = 'npm';
93
+ } else if (lockFile === 'pnpm-lock.yaml') {
94
+ packageManager = 'pnpm';
95
+ } else if (lockFile === 'bun.lock') {
96
+ packageManager = 'bun';
98
97
  }
99
-
100
- throw new Error('Unknown lock file');
101
- };
98
+ assert(packageManager);
99
+ return { packageManager, lockFile };
100
+ }