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

Replace validate-npm-package-name with a regexp #954

Merged
merged 2 commits into from May 6, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-llamas-chew.md
@@ -0,0 +1,5 @@
---
'sku': patch
---

Replace `validate-npm-package-name` dependency with a regexp
1 change: 0 additions & 1 deletion packages/sku/package.json
Expand Up @@ -118,7 +118,6 @@
"terser-webpack-plugin": "^5.1.4",
"tree-kill": "^1.2.1",
"typescript": "~5.3.0",
"validate-npm-package-name": "^5.0.0",
"webpack": "^5.52.0",
"webpack-bundle-analyzer": "^4.6.1",
"webpack-dev-server": "^5.0.2",
Expand Down
23 changes: 11 additions & 12 deletions packages/sku/scripts/init.js
Expand Up @@ -11,7 +11,6 @@ const chalk = require('chalk');
const fs = require('node:fs/promises');
const { posix: path } = require('node:path');
const { isEmptyDir } = require('../lib/isEmptyDir');
const validatePackageName = require('validate-npm-package-name');
const dedent = require('dedent');
const { setCwd } = require('../lib/cwd');
const prettierWrite = require('../lib/runPrettier').write;
Expand Down Expand Up @@ -48,6 +47,11 @@ const getTemplateFileDestinationFromRoot =
return path.join(projectRoot, filePathRelativeToTemplate);
};

// Copied from `package-name-regex@4.0.0`
// See https://github.com/dword-design/package-name-regex/blob/acae7d482b1d03379003899df4d484238625364d/src/index.js#L1-L2
const packageNameRegex =
/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;

(async () => {
const projectName = args.argv[0];

Expand Down Expand Up @@ -89,21 +93,16 @@ const getTemplateFileDestinationFromRoot =
'braid-design-system',
].sort();

const {
validForNewPackages,
errors = [],
warnings = [],
} = validatePackageName(appName);
const isValidPackageName = packageNameRegex.test(appName);

if (!validForNewPackages) {
if (!isValidPackageName) {
console.error(dedent`
Could not create a project called ${chalk.red(`"${appName}"`)} \
because of npm naming restrictions:
Could not create a project called ${chalk.red(
`"${appName}"`,
)} because of npm naming restrictions. \
Please see https://docs.npmjs.com/cli/configuring-npm/package-json for package name rules.
`);

const results = [...errors, ...warnings];
results.forEach((result) => console.error(chalk.red(` * ${result}`)));

process.exit(1);
}

Expand Down
44 changes: 1 addition & 43 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.