From 0d82461c7df314341f8b04ba74511653cf2230c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Tue, 25 Jun 2024 04:19:50 -0300 Subject: [PATCH] fix(watch): map line-breaking imports (#463) --- src/services/map-tests.ts | 6 +++++- test/unit/map-tests.test.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/services/map-tests.ts b/src/services/map-tests.ts index f30717ea..d2229e73 100644 --- a/src/services/map-tests.ts +++ b/src/services/map-tests.ts @@ -20,7 +20,11 @@ export const getDeepImports = (content: string): Set => { const lines = content.split('\n'); for (const line of lines) { - if (line.includes('import') || line.includes('require')) { + if ( + line.indexOf('import') !== -1 || + line.indexOf('require') !== -1 || + line.indexOf(' from ') !== -1 + ) { const path = line.match(/['"](\.{1,2}\/[^'"]+)['"]/); if (path) paths.add(normalizePath(path[1].replace(extFilter, ''))); diff --git a/test/unit/map-tests.test.ts b/test/unit/map-tests.test.ts index aa9171b2..974ef464 100644 --- a/test/unit/map-tests.test.ts +++ b/test/unit/map-tests.test.ts @@ -103,6 +103,20 @@ test(async () => { import './k'; import './l.js'; import('./m.js'); + import { + moduleA, + moduleB, + } from 'some-c'; + import { + moduleA, + moduleB, + } from './n.js'; + import '../../o.js'; + import { + moduleA, + moduleB, + } from '../p.js'; + import('../q.js'); ` ), new Set([ @@ -119,6 +133,10 @@ test(async () => { 'k', 'l', 'm', + 'n', + 'o', + 'p', + 'q', ]), 'import' ); @@ -141,6 +159,7 @@ test(async () => { require('./k'); require('./l.js'); require('./m.js').default; + const { some } = require('../../../n.mjs'); ` ), new Set([ @@ -157,6 +176,7 @@ test(async () => { 'k', 'l', 'm', + 'n', ]), 'require' );