Skip to content

Commit

Permalink
fix(watch): map line-breaking imports (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Jun 25, 2024
1 parent 0c27c4e commit 0d82461
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/services/map-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export const getDeepImports = (content: string): Set<string> => {
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, '')));
Expand Down
20 changes: 20 additions & 0 deletions test/unit/map-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -119,6 +133,10 @@ test(async () => {
'k',
'l',
'm',
'n',
'o',
'p',
'q',
]),
'import'
);
Expand All @@ -141,6 +159,7 @@ test(async () => {
require('./k');
require('./l.js');
require('./m.js').default;
const { some } = require('../../../n.mjs');
`
),
new Set([
Expand All @@ -157,6 +176,7 @@ test(async () => {
'k',
'l',
'm',
'n',
]),
'require'
);
Expand Down

0 comments on commit 0d82461

Please sign in to comment.