Skip to content

Commit

Permalink
feat: refactor module resolution (#1414)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 36 changed files with 395 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import * as path from 'path';
import path from 'path';
import { Plugin } from 'rollup';
import { ModuleResolutionErrors, generateCompilerError } from '@lwc/errors';

Expand Down
9 changes: 6 additions & 3 deletions packages/@lwc/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
"@lwc/template-compiler": "1.0.2"
},
"lwc": {
"modules": {
"lwc": "dist/engine.js"
}
"modules": [
{
"name": "lwc",
"path": "dist/engine.js"
}
]
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 0 additions & 3 deletions packages/@lwc/module-resolver/CONTRIBUTING.md

This file was deleted.

3 changes: 0 additions & 3 deletions packages/@lwc/module-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"build": "tsc"
},
"license": "MIT",
"dependencies": {
"fast-glob": "~2.2.6"
},
"files": [
"dist/"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const x = 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const x = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"modules": [
{
"name": "custom-module",
"path": "custom/module.js"
}
]
}

This file was deleted.

Empty file.

This file was deleted.

Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"modules": [
"@lwc/engine",
"@lwc/wire-service",
"@lwc/synthetic-shadow"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"modules": [
"module-entries/"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const test = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>

</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const test = 1;

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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']);
});
});
Loading

0 comments on commit ce73c8e

Please sign in to comment.