Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop backing up the node_modules folder #962

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
.eslintrc.js

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

Expand Down
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
.gitkeep

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

Expand Down
27 changes: 3 additions & 24 deletions lib/dependency-manager-adapters/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ module.exports = CoreObject.extend({
configKey: 'npm',
packageJSON: 'package.json',
packageJSONBackupFileName: 'package.json.ember-try',
nodeModules: 'node_modules',
nodeModulesBackupLocation: '.node_modules.ember-try',
npmShrinkWrap: 'npm-shrinkwrap.json',
npmShrinkWrapBackupFileName: 'npm-shrinkwrap.json.ember-try',
packageLock: 'package-lock.json',
Expand Down Expand Up @@ -64,10 +62,7 @@ module.exports = CoreObject.extend({

debug('Remove backup package.json and node_modules');

let cleanupTasks = [
rimraf(path.join(this.cwd, this.packageJSONBackupFileName)),
rimraf(path.join(this.cwd, this.nodeModulesBackupLocation)),
];
let cleanupTasks = [rimraf(path.join(this.cwd, this.packageJSONBackupFileName))];

if (fs.existsSync(path.join(this.cwd, this.yarnLockBackupFileName))) {
cleanupTasks.push(rimraf(path.join(this.cwd, this.yarnLockBackupFileName)));
Expand Down Expand Up @@ -104,7 +99,7 @@ module.exports = CoreObject.extend({
},

_findCurrentVersionOf(packageName) {
let filename = path.join(this.cwd, this.nodeModules, packageName, this.packageJSON);
let filename = path.join(this.cwd, 'node_modules', packageName, this.packageJSON);
if (fs.existsSync(filename)) {
return JSON.parse(fs.readFileSync(filename)).version;
} else {
Expand Down Expand Up @@ -229,13 +224,6 @@ module.exports = CoreObject.extend({
),
];

let nodeModulesBackupLocation = path.join(this.cwd, this.nodeModulesBackupLocation);
if (fs.existsSync(nodeModulesBackupLocation)) {
restoreTasks.push(
copy(nodeModulesBackupLocation, path.join(this.cwd, this.nodeModules), { clobber: true })
);
}

let yarnLockBackupFileName = path.join(this.cwd, this.yarnLockBackupFileName);
if (fs.existsSync(yarnLockBackupFileName)) {
restoreTasks.push(copy(yarnLockBackupFileName, path.join(this.cwd, this.yarnLock)));
Expand All @@ -251,7 +239,7 @@ module.exports = CoreObject.extend({
restoreTasks.push(copy(packageLockBackupFileName, path.join(this.cwd, this.packageLock)));
}

return Promise.all(restoreTasks);
return Promise.all(restoreTasks).then(() => this._install());
},

_backupOriginalDependencies() {
Expand All @@ -264,15 +252,6 @@ module.exports = CoreObject.extend({
),
];

let nodeModulesPath = path.join(this.cwd, this.nodeModules);
if (fs.existsSync(nodeModulesPath)) {
backupTasks.push(
copy(nodeModulesPath, path.join(this.cwd, this.nodeModulesBackupLocation), {
clobber: true,
})
);
}

let yarnLockPath = path.join(this.cwd, this.yarnLock);
if (fs.existsSync(yarnLockPath)) {
backupTasks.push(copy(yarnLockPath, path.join(this.cwd, this.yarnLockBackupFileName)));
Expand Down
1 change: 0 additions & 1 deletion smoke-test-app/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
Expand Down
1 change: 0 additions & 1 deletion smoke-test-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
Expand Down
1 change: 0 additions & 1 deletion smoke-test-app/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
.gitkeep

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
Expand Down
1 change: 0 additions & 1 deletion smoke-test-app/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
.lint-todo/

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
Expand Down
18 changes: 0 additions & 18 deletions test/dependency-manager-adapters/npm-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('npmAdapter', () => {
describe('#setup', () => {
it('backs up the package.json file and node_modules', async () => {
fs.mkdirSync('node_modules');
writeJSONFile('node_modules/prove-it.json', { originalNodeModules: true });
writeJSONFile('package.json', { originalPackageJSON: true });

let adapter = new NpmAdapter({ cwd: tmpdir });
Expand All @@ -39,14 +38,10 @@ describe('npmAdapter', () => {
assertFileContainsJSON(path.join(tmpdir, 'package.json.ember-try'), {
originalPackageJSON: true,
});
assertFileContainsJSON(path.join(tmpdir, '.node_modules.ember-try/prove-it.json'), {
originalNodeModules: true,
});
});

it('backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist', async () => {
fs.mkdirSync('node_modules');
writeJSONFile('node_modules/prove-it.json', { originalNodeModules: true });
writeJSONFile('package.json', { originalPackageJSON: true });
writeJSONFile('yarn.lock', { originalYarnLock: true });
writeJSONFile('npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
Expand All @@ -58,9 +53,6 @@ describe('npmAdapter', () => {
assertFileContainsJSON(path.join(tmpdir, 'package.json.ember-try'), {
originalPackageJSON: true,
});
assertFileContainsJSON(path.join(tmpdir, '.node_modules.ember-try/prove-it.json'), {
originalNodeModules: true,
});
assertFileContainsJSON(path.join(tmpdir, 'yarn.lock.ember-try'), {
originalYarnLock: true,
});
Expand Down Expand Up @@ -347,23 +339,16 @@ describe('npmAdapter', () => {
it('replaces the package.json with the backed up version', async () => {
writeJSONFile('package.json.ember-try', { originalPackageJSON: true });
writeJSONFile('package.json', { originalPackageJSON: false });
fs.mkdirSync('.node_modules.ember-try');
writeJSONFile('.node_modules.ember-try/prove-it.json', { originalNodeModules: true });

let adapter = new NpmAdapter({ cwd: tmpdir });
await adapter._restoreOriginalDependencies();

assertFileContainsJSON(path.join(tmpdir, 'package.json'), { originalPackageJSON: true });
assertFileContainsJSON(path.join(tmpdir, 'node_modules/prove-it.json'), {
originalNodeModules: true,
});
});

it('replaces the yarn.lock, npm-shrinkwrap.json and package-lock.json with the backed up version if they exist', async () => {
writeJSONFile('package.json.ember-try', { originalPackageJSON: true });
writeJSONFile('package.json', { originalPackageJSON: false });
fs.mkdirSync('.node_modules.ember-try');
writeJSONFile('.node_modules.ember-try/prove-it.json', { originalNodeModules: true });
writeJSONFile('yarn.lock.ember-try', { originalYarnLock: true });
writeJSONFile('yarn.lock', { originalYarnLock: false });
writeJSONFile('npm-shrinkwrap.json.ember-try', { originalNpmShrinkWrap: true });
Expand All @@ -375,9 +360,6 @@ describe('npmAdapter', () => {
await adapter._restoreOriginalDependencies();

assertFileContainsJSON(path.join(tmpdir, 'package.json'), { originalPackageJSON: true });
assertFileContainsJSON(path.join(tmpdir, 'node_modules/prove-it.json'), {
originalNodeModules: true,
});
assertFileContainsJSON(path.join(tmpdir, 'yarn.lock'), { originalYarnLock: true });
assertFileContainsJSON(path.join(tmpdir, 'npm-shrinkwrap.json'), {
originalNpmShrinkWrap: true,
Expand Down
5 changes: 0 additions & 5 deletions test/dependency-manager-adapters/pnpm-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('pnpm Adapter', () => {
it('backs up the `package.json` and `pnpm-lock.yaml` files', async () => {
await fs.outputJson('package.json', { originalPackageJSON: true });
await fs.outputFile('pnpm-lock.yaml', 'originalYAML: true\n');
await fs.outputJson('node_modules/prove-it.json', { originalNodeModules: true });

let adapter = new PnpmAdapter({ cwd: tmpdir });
await adapter.setup();
Expand All @@ -37,12 +36,10 @@ describe('pnpm Adapter', () => {
expect(await fs.readFile('pnpm-lock.ember-try.yaml', 'utf-8')).to.equal(
'originalYAML: true\n'
);
expect(fs.existsSync('.node_modules.ember-try')).to.be.false;
});

it('ignores missing `pnpm-lock.yaml` files', async () => {
await fs.outputJson('package.json', { originalPackageJSON: true });
await fs.outputJson('node_modules/prove-it.json', { originalNodeModules: true });

let adapter = new PnpmAdapter({ cwd: tmpdir });
await adapter.setup();
Expand All @@ -51,7 +48,6 @@ describe('pnpm Adapter', () => {
originalPackageJSON: true,
});
expect(fs.existsSync('pnpm-lock.ember-try.yaml')).to.be.false;
expect(fs.existsSync('.node_modules.ember-try')).to.be.false;
});
});

Expand Down Expand Up @@ -145,7 +141,6 @@ describe('pnpm Adapter', () => {
expect(await fs.readFile('pnpm-lock.yaml', 'utf-8')).to.equal('originalYAML: true\n');
expect(fs.existsSync('package.json.ember-try')).to.be.false;
expect(fs.existsSync('pnpm-lock.ember-try.yaml')).to.be.false;
expect(fs.existsSync('.node_modules.ember-try')).to.be.false;

expect(runCount).to.equal(1);
});
Expand Down
34 changes: 0 additions & 34 deletions test/dependency-manager-adapters/workspace-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('workspaceAdapter', () => {
fs.ensureDirSync('packages/test/node_modules');

writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: true });

return new WorkspaceAdapter({
cwd: tmpdir,
Expand All @@ -44,10 +43,6 @@ describe('workspaceAdapter', () => {
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package.json.ember-try'), {
originalPackageJSON: true,
});
assertFileContainsJSON(
path.join(tmpdir, 'packages/test/.node_modules.ember-try/prove-it.json'),
{ originalNodeModules: true }
);
});
});

Expand All @@ -63,7 +58,6 @@ describe('workspaceAdapter', () => {
fs.ensureDirSync('packages/test/node_modules');

writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: true });

return new WorkspaceAdapter({
cwd: tmpdir,
Expand All @@ -74,18 +68,13 @@ describe('workspaceAdapter', () => {
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package.json.ember-try'), {
originalPackageJSON: true,
});
assertFileContainsJSON(
path.join(tmpdir, 'packages/test/.node_modules.ember-try/prove-it.json'),
{ originalNodeModules: true }
);
});
});

it('backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist', () => {
fs.ensureDirSync('packages/test/node_modules');

writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: true });
writeJSONFile('packages/test/yarn.lock', { originalYarnLock: true });
writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
writeJSONFile('packages/test/package-lock.json', { originalPackageLock: true });
Expand All @@ -98,10 +87,6 @@ describe('workspaceAdapter', () => {
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package.json.ember-try'), {
originalPackageJSON: true,
});
assertFileContainsJSON(
path.join(tmpdir, 'packages/test/.node_modules.ember-try/prove-it.json'),
{ originalNodeModules: true }
);
assertFileContainsJSON(path.join(tmpdir, 'packages/test/yarn.lock.ember-try'), {
originalYarnLock: true,
});
Expand Down Expand Up @@ -247,36 +232,26 @@ describe('workspaceAdapter', () => {
fs.ensureDirSync('packages/test/node_modules');

writeJSONFile('packages/test/package.json', { originalPackageJSON: false });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: false });

let workspaceAdapter = new WorkspaceAdapter({
cwd: tmpdir,
useYarnCommand: true,
run: () => Promise.resolve(),
});

fs.ensureDirSync('packages/test/.node_modules.ember-try');

writeJSONFile('packages/test/package.json.ember-try', { originalPackageJSON: true });
writeJSONFile('packages/test/.node_modules.ember-try/prove-it.json', {
originalNodeModules: true,
});

return workspaceAdapter.cleanup().then(() => {
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package.json'), {
originalPackageJSON: true,
});
assertFileContainsJSON(path.join(tmpdir, 'packages/test/node_modules/prove-it.json'), {
originalNodeModules: true,
});
});
});

it('replaces the package.json with the backed up version', () => {
fs.ensureDirSync('packages/test/node_modules');

writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: true });

let workspaceAdapter = new WorkspaceAdapter({
cwd: tmpdir,
Expand All @@ -288,25 +263,20 @@ describe('workspaceAdapter', () => {
.setup()
.then(() => {
writeJSONFile('packages/test/package.json', { originalPackageJSON: false });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: true });

return workspaceAdapter.cleanup();
})
.then(() => {
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package.json'), {
originalPackageJSON: true,
});
assertFileContainsJSON(path.join(tmpdir, 'packages/test/node_modules/prove-it.json'), {
originalNodeModules: true,
});
});
});

it('replaces the yarn.lock, npm-shrinkwrap.json and package-lock.json with the backed up version if they exist', () => {
fs.ensureDirSync('packages/test/node_modules');

writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: true });
writeJSONFile('packages/test/yarn.lock', { originalYarnLock: true });
writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: true });
writeJSONFile('packages/test/package-lock.json', { originalPackageLock: true });
Expand All @@ -321,7 +291,6 @@ describe('workspaceAdapter', () => {
.setup()
.then(() => {
writeJSONFile('packages/test/package.json', { originalPackageJSON: false });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: true });
writeJSONFile('packages/test/yarn.lock', { originalYarnLock: false });
writeJSONFile('packages/test/npm-shrinkwrap.json', { originalNpmShrinkWrap: false });
writeJSONFile('packages/test/package-lock.json', { originalPackageLock: false });
Expand All @@ -332,9 +301,6 @@ describe('workspaceAdapter', () => {
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package.json'), {
originalPackageJSON: true,
});
assertFileContainsJSON(path.join(tmpdir, 'packages/test/node_modules/prove-it.json'), {
originalNodeModules: true,
});
assertFileContainsJSON(path.join(tmpdir, 'packages/test/yarn.lock'), {
originalYarnLock: true,
});
Expand Down