Skip to content

Commit

Permalink
Fix: Add missing pre/post hooks for pack (#4177) (#4193)
Browse files Browse the repository at this point in the history
**Summary**
Yarn wouldn't run the `prepack` and `postpack` scripts, as it is expected when `pack` is ran (#4177).
This PR adds those missing calls and updates tests accordingly.

**Test plan**
Added tests.
  • Loading branch information
joaolucasl authored and BYK committed Aug 18, 2017
1 parent a9e343c commit 4d7043d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"scripts": {
"prepublish": "echo running the prepublish hook",
"prepublishOnly": "echo running the prepublishOnly hook",
"prepare": "echo running the prepare hook"
"prepare": "echo running the prepare hook",
"prepack": "echo running the prepack hook",
"postpack": "echo running the postpack hook"
}
}
}
7 changes: 7 additions & 0 deletions __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ test.concurrent('should run both prepublish and prepare when installing, but not
expect(stdout).not.toMatch(/^running the prepublishOnly hook$/m);
});

test.concurrent('should run both prepack and postpack', async () => {
const stdout = await execCommand('pack', 'lifecycle-scripts');

expect(stdout).toMatch(/^running the prepack hook$/m);
expect(stdout).toMatch(/^running the postpack hook$/m);
});

test.concurrent('should allow setting environment variables via yarnrc', async () => {
const stdout = await execCommand('install', 'yarnrc-env');
expect(stdout).toMatch(/^BAR$/m);
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
const normaliseScope = name => (name[0] === '@' ? name.substr(1).replace('/', '-') : name);
const filename = flags.filename || path.join(config.cwd, `${normaliseScope(pkg.name)}-v${pkg.version}.tgz`);

await config.executeLifecycleScript('prepack');

const stream = await pack(config, config.cwd);

await new Promise((resolve, reject) => {
Expand All @@ -168,5 +170,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
stream.on('close', resolve);
});

await config.executeLifecycleScript('postpack');

reporter.success(reporter.lang('packWroteTarball', filename));
}

0 comments on commit 4d7043d

Please sign in to comment.