Skip to content

Commit

Permalink
feat(publish): remove --require-scripts, keep npm scripts lifecycle (
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Apr 5, 2023
1 parent 5506ea5 commit 6559aec
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 60 deletions.
10 changes: 0 additions & 10 deletions packages/cli/schemas/lerna-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,6 @@
"removePackageFields": {
"$ref": "#/$defs/commandOptions/publish/removePackageFields"
},
"requireScripts": {
"$ref": "#/$defs/commandOptions/publish/requireScripts"
},
"noGitReset": {
"$ref": "#/$defs/commandOptions/publish/noGitReset"
},
Expand Down Expand Up @@ -911,9 +908,6 @@
"removePackageFields": {
"$ref": "#/$defs/commandOptions/publish/removePackageFields"
},
"requireScripts": {
"$ref": "#/$defs/commandOptions/publish/requireScripts"
},
"noGitReset": {
"$ref": "#/$defs/commandOptions/publish/noGitReset"
},
Expand Down Expand Up @@ -1217,10 +1211,6 @@
},
"description": "Remove fields from each package.json before publishing them to the registry, removing fields from a complex object is also supported via the dot notation (ie 'scripts.build')"
},
"requireScripts": {
"type": "boolean",
"description": "@deprecated During `lerna publish`, when true, execute ./scripts/prepublish.js and ./scripts/postpublish.js, relative to package root."
},
"noGitReset": {
"type": "boolean",
"description": "During `lerna publish`, when true, do not reset changes to working tree after publishing is complete."
Expand Down
7 changes: 0 additions & 7 deletions packages/cli/src/cli-commands/cli-publish-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ export default {
'Remove fields from each package.json before publishing them to the registry, removing fields from a complex object is also supported via the dot notation (ie "scripts.build").',
type: 'array',
},
'require-scripts': {
describe: 'Execute ./scripts/prepublish.js and ./scripts/postpublish.js, relative to package root.',
type: 'boolean',
},
'no-git-reset': {
describe: 'Do not reset changes to working tree after publishing is complete.',
type: 'boolean',
Expand Down Expand Up @@ -194,9 +190,6 @@ export default {
log.warn('deprecated', '--npm-tag has been renamed --dist-tag');
}

if (argv.requireScripts) {
log.warn('deprecated', '--require-scripts has been deprecated and will be removed in next major');
}
/* eslint-enable no-param-reassign */

return argv;
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/models/command-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,6 @@ export interface PublishCommandOption extends VersionCommandOption {
/** Remove fields from each package.json before publishing them to the registry, removing fields from a complex object is also supported via the dot notation (ie "scripts.build") */
removePackageFields?: string[];

/** @deprecated Execute ./scripts/prepublish.js and ./scripts/postpublish.js, relative to package root. */
requireScripts?: boolean;

/** Do not reset changes to working tree after publishing is complete. */
noGitReset?: boolean;

Expand Down
16 changes: 0 additions & 16 deletions packages/publish/src/__tests__/publish-lifecycle-scripts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { runLifecycle } from '@lerna-lite/core';
// helpers
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { loggingOutput } from '@lerna-test/helpers/logging-output';
import { commandRunner, initFixtureFactory } from '@lerna-test/helpers';

const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -181,18 +180,3 @@ describe('lifecycle scripts', () => {
);
});
});

// @deprecated, execScript should be removed since requireScripts is deprecated
describe('execScript', () => {
it('execute --require-scripts but fails since scripts folder does not exist and log error with script not found message is shown', async () => {
const cwd = await initFixture('lifecycle');

await lernaPublish(cwd)('--require-scripts');
const logInfoMessages = loggingOutput('info');
const logSillyMessages = loggingOutput('silly');

expect(logInfoMessages).toContain('enabled');
expect(logSillyMessages.filter((x) => x.includes('No prepublish script found at'))).toBeTruthy();
expect(logSillyMessages.filter((x) => x.includes('No postpublish script found at'))).toBeTruthy();
});
});
24 changes: 0 additions & 24 deletions packages/publish/src/publish-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { outputFileSync, removeSync } from 'fs-extra/esm';
import { EOL } from 'node:os';
import { join, relative } from 'node:path';
import crypto from 'crypto';
import { createRequire } from 'node:module';
import normalizePath from 'normalize-path';
import pMap from 'p-map';
import pPipe, { type UnaryFunction } from 'p-pipe';
Expand Down Expand Up @@ -156,11 +155,6 @@ export class PublishCommand extends Command<PublishCommandOption> {
this.logger.info('canary', 'enabled');
}

// @deprecated, to be removed in next major
if (this.options.requireScripts) {
this.logger.info('require-scripts', 'enabled');
}

// npmSession and user-agent are consumed by npm-registry-fetch (via libnpmpublish)
this.logger.verbose('session', this.npmSession);
this.logger.verbose('user-agent', this.userAgent);
Expand Down Expand Up @@ -741,20 +735,6 @@ export class PublishCommand extends Command<PublishCommandOption> {
});
}

// @deprecated, see Lerna PR https://github.com/lerna/lerna/pull/1862/files
execScript(pkg: Package, script: string) {
const scriptLocation = join(pkg.location, 'scripts', script);

try {
const require = createRequire(import.meta.url);
require(scriptLocation);
} catch (ex) {
this.logger.silly('execScript', `No ${script} script found at ${scriptLocation}`);
}

return pkg;
}

removePackageProperties() {
const { removePackageFields } = this.options;

Expand Down Expand Up @@ -843,8 +823,6 @@ export class PublishCommand extends Command<PublishCommandOption> {
const mapper = pPipe(
...(
[
this.options.requireScripts && ((pkg: Package) => this.execScript(pkg, 'prepublish')),

(pkg: Package & { packed: Tarball }) =>
pulseTillDone(packDirectory(pkg, pkg.location, opts)).then((packed: Tarball) => {
tracker.verbose('packed', relative(this.project.rootPath ?? '', pkg.contents));
Expand Down Expand Up @@ -936,8 +914,6 @@ export class PublishCommand extends Command<PublishCommandOption> {
throw err;
});
},

this.options.requireScripts && ((pkg: Package) => this.execScript(pkg, 'postpublish')),
] as UnaryFunction<any, unknown>[]
).filter(Boolean)
);
Expand Down

0 comments on commit 6559aec

Please sign in to comment.