From 167453a4890d61771e49059d514e787da3468148 Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 9 Oct 2023 11:38:05 +0800 Subject: [PATCH] Check packed files for files suggestion --- pkg/src/index.js | 6 ++++++ pkg/tests/fixtures/npmignore/.npmignore | 1 + pkg/tests/fixtures/npmignore/main.js | 1 + pkg/tests/fixtures/npmignore/package.json | 7 +++++++ pkg/tests/fixtures/npmignore/tests/test.js | 1 + pkg/tests/playground.js | 2 ++ 6 files changed, 18 insertions(+) create mode 100644 pkg/tests/fixtures/npmignore/.npmignore create mode 100644 pkg/tests/fixtures/npmignore/main.js create mode 100644 pkg/tests/fixtures/npmignore/package.json create mode 100644 pkg/tests/fixtures/npmignore/tests/test.js diff --git a/pkg/src/index.js b/pkg/src/index.js index c0fab4f..38813a4 100755 --- a/pkg/src/index.js +++ b/pkg/src/index.js @@ -57,6 +57,12 @@ export async function publint({ pkgDir, vfs, level, strict, _packedFiles }) { promiseQueue.push(async () => { for (const p of commonInternalPaths) { const internalPath = vfs.pathJoin(pkgDir, p) + if ( + _packedFiles && + _packedFiles.every((f) => !f.startsWith(internalPath)) + ) { + continue + } if (await vfs.isPathExist(internalPath)) { messages.push({ code: 'USE_FILES', diff --git a/pkg/tests/fixtures/npmignore/.npmignore b/pkg/tests/fixtures/npmignore/.npmignore new file mode 100644 index 0000000..3598c30 --- /dev/null +++ b/pkg/tests/fixtures/npmignore/.npmignore @@ -0,0 +1 @@ +tests \ No newline at end of file diff --git a/pkg/tests/fixtures/npmignore/main.js b/pkg/tests/fixtures/npmignore/main.js new file mode 100644 index 0000000..3ec2bcf --- /dev/null +++ b/pkg/tests/fixtures/npmignore/main.js @@ -0,0 +1 @@ +export const foo = 'This file is ESM, but extension says CJS' diff --git a/pkg/tests/fixtures/npmignore/package.json b/pkg/tests/fixtures/npmignore/package.json new file mode 100644 index 0000000..99a6199 --- /dev/null +++ b/pkg/tests/fixtures/npmignore/package.json @@ -0,0 +1,7 @@ +{ + "name": "publint-npmignore", + "version": "0.0.1", + "private": true, + "type": "module", + "exports": "./main.js" +} \ No newline at end of file diff --git a/pkg/tests/fixtures/npmignore/tests/test.js b/pkg/tests/fixtures/npmignore/tests/test.js new file mode 100644 index 0000000..8c38a5a --- /dev/null +++ b/pkg/tests/fixtures/npmignore/tests/test.js @@ -0,0 +1 @@ +// suggest pkg.files if this file is published diff --git a/pkg/tests/playground.js b/pkg/tests/playground.js index 005c905..f4d9fb7 100644 --- a/pkg/tests/playground.js +++ b/pkg/tests/playground.js @@ -47,6 +47,8 @@ testFixture('exports-module', ['EXPORTS_MODULE_SHOULD_PRECEDE_REQUIRE']) testFixture('publish-config', ['FILE_DOES_NOT_EXIST', 'USE_EXPORTS_BROWSER']) +testFixture('npmignore', []) + testFixture('test-1', [ 'FILE_INVALID_FORMAT', 'TYPES_NOT_EXPORTED',