-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor module resolution (#1414)
* feat: refactor module resolution * fix: refactor base on feedback * fix: overrides * fix: readDir * fix: add copyright * fix: upgrade best and minor fixes
- Loading branch information
Diego Ferreiro Val
authored
Aug 14, 2019
1 parent
850bd12
commit ce73c8e
Showing
36 changed files
with
395 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,6 @@ | |
"build": "tsc" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"fast-glob": "~2.2.6" | ||
}, | ||
"files": [ | ||
"dist/" | ||
], | ||
|
1 change: 1 addition & 0 deletions
1
packages/@lwc/module-resolver/src/__tests__/fixtures/custom-resolution/custom-override.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const x = 2; |
1 change: 1 addition & 0 deletions
1
packages/@lwc/module-resolver/src/__tests__/fixtures/custom-resolution/custom/module.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const x = 1; |
8 changes: 8 additions & 0 deletions
8
packages/@lwc/module-resolver/src/__tests__/fixtures/custom-resolution/lwc.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"modules": [ | ||
{ | ||
"name": "custom-module", | ||
"path": "custom/module.js" | ||
} | ||
] | ||
} |
8 changes: 0 additions & 8 deletions
8
...module-resolver/src/__tests__/fixtures/fake_node_modules/fake-module-package/package.json
This file was deleted.
Oops, something went wrong.
Empty file.
9 changes: 0 additions & 9 deletions
9
...odule-resolver/src/__tests__/fixtures/fake_node_modules/fake-multi-component/package.json
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions
7
packages/@lwc/module-resolver/src/__tests__/fixtures/from-npm/lwc.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"modules": [ | ||
"@lwc/engine", | ||
"@lwc/wire-service", | ||
"@lwc/synthetic-shadow" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/@lwc/module-resolver/src/__tests__/fixtures/lwc.config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"modules": [ | ||
"module-entries/" | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/@lwc/module-resolver/src/__tests__/fixtures/module-entries/ns/cssEntry/cssEntry.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const test = 1; |
3 changes: 3 additions & 0 deletions
3
...es/@lwc/module-resolver/src/__tests__/fixtures/module-entries/ns/htmlEntry/htmlEntry.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
|
||
</template> |
1 change: 1 addition & 0 deletions
1
packages/@lwc/module-resolver/src/__tests__/fixtures/module-entries/ns/jsEntry/jsEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const test = 1; |
3 changes: 0 additions & 3 deletions
3
...esolver/src/__tests__/fixtures/simple-folder-structure/modules/ns/cssModule/cssModule.css
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...__tests__/fixtures/simple-folder-structure/modules/ns/missmatched-name/missmatchedname.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...__tests__/fixtures/simple-folder-structure/modules/ns/prefixed-module-name/module-name.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
.../src/__tests__/fixtures/simple-folder-structure/modules/ns/simple-module/simple-module.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...solver/src/__tests__/fixtures/simple-folder-structure/modules/ns/simpleCmp/simpleCmp.html
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...resolver/src/__tests__/fixtures/simple-folder-structure/modules/ns/simpleCmp/simpleCmp.js
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
packages/@lwc/module-resolver/src/__tests__/resolve-dir-modules.spec.js
This file was deleted.
Oops, something went wrong.
73 changes: 0 additions & 73 deletions
73
packages/@lwc/module-resolver/src/__tests__/resolve-lwc-modules.spec.js
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
packages/@lwc/module-resolver/src/__tests__/resolve.modules.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import path from 'path'; | ||
import { resolveModules } from '../index'; | ||
|
||
const FIXTURE_MODULE_ENTRIES = ['ns/cssEntry', 'ns/htmlEntry', 'ns/jsEntry']; | ||
|
||
describe('resolve modules', () => { | ||
it('from directory', () => { | ||
const modules = resolveModules({ | ||
rootDir: __dirname, | ||
modules: ['fixtures/module-entries'], | ||
}); | ||
const specifiers = modules.map(m => m.specifier); | ||
expect(specifiers).toStrictEqual(FIXTURE_MODULE_ENTRIES); | ||
}); | ||
|
||
it('from config', () => { | ||
const moduleDir = path.join(__dirname, 'fixtures'); | ||
const modules = resolveModules({ rootDir: moduleDir }); | ||
const specifiers = modules.map(m => m.specifier); | ||
expect(specifiers).toStrictEqual(FIXTURE_MODULE_ENTRIES); | ||
}); | ||
|
||
it('from config resolving to npm', () => { | ||
const moduleDir = path.join(__dirname, 'fixtures/from-npm'); | ||
const modules = resolveModules({ rootDir: moduleDir }); | ||
const specifiers = modules.map(m => m.specifier); | ||
expect(specifiers).toStrictEqual(['lwc', 'wire-service', '@lwc/synthetic-shadow']); | ||
}); | ||
|
||
it('from config resolving to custom modules', () => { | ||
const moduleDir = path.join(__dirname, 'fixtures/custom-resolution'); | ||
const modules = resolveModules({ rootDir: moduleDir }); | ||
const specifiers = modules.map(m => m.specifier); | ||
expect(specifiers).toStrictEqual(['custom-module']); | ||
}); | ||
|
||
it('with configuration overrides resolving to custom modules', () => { | ||
const moduleDir = path.join(__dirname, 'fixtures/custom-resolution'); | ||
const modules = resolveModules({ | ||
rootDir: moduleDir, | ||
modules: [{ name: 'custom-module', path: 'custom-override.js' }], | ||
}); | ||
const specifiers = modules.map(m => m.specifier); | ||
const entries = modules.map(m => m.entry); | ||
expect(specifiers).toStrictEqual(['custom-module']); | ||
expect(entries).toStrictEqual([path.join(moduleDir, 'custom-override.js')]); | ||
}); | ||
|
||
it('from api configuration', () => { | ||
const modules = resolveModules({ modules: ['@lwc/engine'] }); | ||
const specifiers = modules.map(m => m.specifier); | ||
expect(specifiers).toStrictEqual(['lwc']); | ||
}); | ||
}); |
Oops, something went wrong.