From 9b11d8ba6c5fe708215357ce3e9c839dc0a60bb7 Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Mon, 10 Apr 2023 15:52:42 +1000 Subject: [PATCH] Fix tests --- packages/cli/src/build/__tests__/basic.ts | 2 +- packages/cli/src/build/__tests__/other.ts | 7 +++---- packages/cli/src/rollup-plugins/resolve.ts | 22 ++++++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/build/__tests__/basic.ts b/packages/cli/src/build/__tests__/basic.ts index 926f070a..2895ea44 100644 --- a/packages/cli/src/build/__tests__/basic.ts +++ b/packages/cli/src/build/__tests__/basic.ts @@ -1241,7 +1241,7 @@ test("importing css fails with a nice error", async () => { "src/blah.css": "", }); await expect(build(dir)).rejects.toMatchInlineSnapshot( - `[Error: 🎁 @scope/test only .ts, .tsx, .js, .jsx, and .json files can be imported but "/private/var/folders/ct/tgr1gzss4wx58r9t7f0yp8_00000gn/T/51ae39dfcd9235458107c14021cd4c05/src/blah.css" is imported in "src/index.js"]` + `[Error: 🎁 @scope/test only .ts, .tsx, .js, .jsx, and .json files can be imported but "blah.css" is imported in "src/index.js"]` ); }); diff --git a/packages/cli/src/build/__tests__/other.ts b/packages/cli/src/build/__tests__/other.ts index 6329a109..0553e662 100644 --- a/packages/cli/src/build/__tests__/other.ts +++ b/packages/cli/src/build/__tests__/other.ts @@ -517,10 +517,9 @@ test("module imported outside package directory", async () => { try { await build(tmpPath); } catch (err) { - expect(err.message).toMatchInlineSnapshot(` - "🎁 @imports-outside-pkg-dir/pkg-a all relative imports in a package should only import modules inside of their package directory but "src/index.js" is importing "../../some-file" - 🎁 @imports-outside-pkg-dir/pkg-a all relative imports in a package should only import modules inside of their package directory but "src/index.js" is importing "/private/var/folders/ct/tgr1gzss4wx58r9t7f0yp8_00000gn/T/7b8193c2854b775119af269533486790/some-file.js"" - `); + expect(err.message).toMatchInlineSnapshot( + `"🎁 @imports-outside-pkg-dir/pkg-a all relative imports in a package should only import modules inside of their package directory but "src/index.js" is importing "../../some-file""` + ); return; } expect(true).toBe(false); diff --git a/packages/cli/src/rollup-plugins/resolve.ts b/packages/cli/src/rollup-plugins/resolve.ts index 86bfac45..e0161262 100644 --- a/packages/cli/src/rollup-plugins/resolve.ts +++ b/packages/cli/src/rollup-plugins/resolve.ts @@ -43,7 +43,11 @@ export function resolveErrorsPlugin( if (resolved.id.startsWith(pkg.directory)) { if (!resolved.external && !allowedExtensionRegex.test(resolved.id)) { warnings.add( - `only .ts, .tsx, .js, .jsx, and .json files can be imported but "${source}" is imported in ${ + `only .ts, .tsx, .js, .jsx, and .json files can be imported but "${ + importer === undefined + ? source + : normalizePath(path.relative(path.dirname(importer), source)) + }" is imported in ${ importer ? `"${normalizePath(path.relative(pkg.directory, importer))}"` : "a module" @@ -55,13 +59,15 @@ export function resolveErrorsPlugin( return resolved; } if (isUmd) return resolved; - warnings.add( - `all relative imports in a package should only import modules inside of their package directory but ${ - importer - ? `"${normalizePath(path.relative(pkg.directory, importer))}"` - : "a module" - } is importing "${source}"` - ); + if (resolved.id !== source) { + warnings.add( + `all relative imports in a package should only import modules inside of their package directory but ${ + importer + ? `"${normalizePath(path.relative(pkg.directory, importer))}"` + : "a module" + } is importing "${source}"` + ); + } return false; },