Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow typescript file extension #1135

Merged
merged 8 commits into from
Mar 28, 2019
Merged

Conversation

diervo
Copy link
Contributor

@diervo diervo commented Mar 26, 2019

Details

Refactor module resolver and compile to allow typescript extension .ts (note that is just the extension we don't allow TS grammar).

Also this PR migrates module-resolver to typescript preparing for future changes.

@diervo diervo requested a review from pmdartus March 26, 2019 03:42
@diervo diervo changed the title feat: allow typescript extension feat: allow typescript file extension Mar 26, 2019
@salesforce-best-lwc-internal

This comment has been minimized.

packages/@lwc/module-resolver/src/node-modules-paths.ts Outdated Show resolved Hide resolved

export default function nodeModulesPaths(
basedir: string,
{ moduleDirectory }: NodeModulesConfig = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid defaulting internal value when not needed.

Suggested change
{ moduleDirectory }: NodeModulesConfig = {}
{ moduleDirectory }: NodeModulesConfig

packages/@lwc/module-resolver/src/node-modules-paths.ts Outdated Show resolved Hide resolved
packages/@lwc/module-resolver/src/index.ts Outdated Show resolved Hide resolved
@@ -97,13 +112,12 @@ function resolveModules(modules, opts) {
}
}

function resolveLwcNpmModules(options = {}) {
function resolveLwcNpmModules(options: ModuleResolverConfig = {}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove common js style import at the end of the file.

Suggested change
function resolveLwcNpmModules(options: ModuleResolverConfig = {}) {
export function resolveLwcNpmModules(options: ModuleResolverConfig = {}) {

@@ -97,13 +112,12 @@ function resolveModules(modules, opts) {
}
}

function resolveLwcNpmModules(options = {}) {
function resolveLwcNpmModules(options: ModuleResolverConfig = {}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ModuleResolverConfig should be normalized and we should initialize the options field to avoid doing branching in the resolver.

You can use Partial for this (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#mapped-types).

export interface ModuleResolverConfig {
    moduleDirectories: string[];
    rootDir: string;
}

function resolveLwcNpmModules(options: Partial<ModuleResolverConfig> = {}) {
    const normalizedOptions: ModuleResolverConfig = normalizeOptions(options);
}

describe('test typescript like bundle', () => {
test('test typescript extension', async () => {
const customConfig = {
name: 'typescript.ts',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name should not include extension it should not be a valid LWC module name.


test('test typescript grammar should fail', async () => {
const customConfig = {
name: 'typescript-typed.ts',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name should not include extension it should not be a valid LWC module name.

packages/@lwc/module-resolver/tsconfig.json Show resolved Hide resolved
@pmdartus
Copy link
Member

@diervo Since the compiler doesn't provide pre-processor hooks to run tsc or babel with the typescript preset, how do you typescript feat into the compiler?

@salesforce-best-lwc-internal

This comment has been minimized.

@salesforce-best-lwc-internal

This comment has been minimized.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 8bd4776 | Target commit: 8eec448

lwc-engine-benchmark

table-append-1k metric base(8bd4776) target(8eec448) trend
benchmark-table/append/1k duration 155.10 (±4.80 ms) 150.45 (±4.15 ms) -4.7ms (3.0%) 👍
table-clear-1k metric base(8bd4776) target(8eec448) trend
benchmark-table/clear/1k duration 10.45 (±0.45 ms) 10.60 (±0.70 ms) +0.2ms (1.4%) 👌
table-create-10k metric base(8bd4776) target(8eec448) trend
benchmark-table/create/10k duration 881.25 (±6.65 ms) 882.05 (±6.35 ms) +0.8ms (0.1%) 👌
table-create-1k metric base(8bd4776) target(8eec448) trend
benchmark-table/create/1k duration 117.55 (±2.40 ms) 117.65 (±3.10 ms) +0.1ms (0.1%) 👌
table-update-10th-1k metric base(8bd4776) target(8eec448) trend
benchmark-table/update-10th/1k duration 78.25 (±5.60 ms) 79.95 (±1.60 ms) +1.7ms (2.2%) 👎
tablecmp-append-1k metric base(8bd4776) target(8eec448) trend
benchmark-table-component/append/1k duration 227.20 (±12.35 ms) 223.90 (±10.90 ms) -3.3ms (1.5%) 👌
tablecmp-clear-1k metric base(8bd4776) target(8eec448) trend
benchmark-table-component/clear/1k duration 6.35 (±1.15 ms) 6.50 (±1.05 ms) +0.2ms (2.4%) 👌
tablecmp-create-10k metric base(8bd4776) target(8eec448) trend
benchmark-table-component/create/10k duration 1739.25 (±12.45 ms) 1711.40 (±11.10 ms) -27.8ms (1.6%) 👍
tablecmp-create-1k metric base(8bd4776) target(8eec448) trend
benchmark-table-component/create/1k duration 210.60 (±4.20 ms) 208.45 (±4.95 ms) -2.2ms (1.0%) 👌
tablecmp-update-10th-1k metric base(8bd4776) target(8eec448) trend
benchmark-table-component/update-10th/1k duration 67.20 (±5.55 ms) 66.15 (±3.90 ms) -1.0ms (1.6%) 👌
wc-append-1k metric base(8bd4776) target(8eec448) trend
benchmark-table-wc/append/1k duration 236.30 (±20.35 ms) 233.85 (±15.60 ms) -2.5ms (1.0%) 👌
wc-clear-1k metric base(8bd4776) target(8eec448) trend
benchmark-table-wc/clear/1k duration 11.20 (±1.65 ms) 10.55 (±1.40 ms) -0.6ms (5.8%) 👌
wc-create-10k metric base(8bd4776) target(8eec448) trend
benchmark-table-wc/create/10k duration 1890.35 (±25.65 ms) 1848.70 (±16.75 ms) -41.6ms (2.2%) 👍
wc-create-1k metric base(8bd4776) target(8eec448) trend
benchmark-table-wc/create/1k duration 214.80 (±5.70 ms) 214.65 (±6.00 ms) -0.2ms (0.1%) 👌
wc-update-10th-1k metric base(8bd4776) target(8eec448) trend
benchmark-table-wc/update-10th/1k duration 67.85 (±4.35 ms) 65.20 (±5.20 ms) -2.7ms (3.9%) 👍

@pmdartus pmdartus requested a review from apapko March 27, 2019 13:11
Copy link
Collaborator

@apapko apapko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! One ask to keep the original expected in module-resolver.spec.ts

@@ -42,7 +42,8 @@ module.exports = function postProcess({ types: t }) {

function getBaseName({ file }) {
const classPath = file.opts.filename;
return basename(classPath, '.js');
const ext = extname(classPath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to perform extension validation to only allow .js and .ts or should module-resolver fail on its own

message: expect.stringContaining(
'Failed to resolve import "./lib/foo" from "foo.js". Please add "lib/foo.js" file to the component folder.'
),
message: expect.stringContaining('Failed to resolve'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we retain the original messages here? We've added logic to provide better error messages and to explicitly state the missing files in the error, therefore i'd like to make sure that all the dynamic peaces are tested.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: c0776e4 | Target commit: a61a19a

lwc-engine-benchmark

table-append-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table/append/1k duration 155.85 (±4.30 ms) 151.55 (±3.70 ms) -4.3ms (2.8%) 👍
table-clear-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table/clear/1k duration 11.20 (±0.85 ms) 10.75 (±0.75 ms) -0.4ms (4.0%) 👍
table-create-10k metric base(c0776e4) target(a61a19a) trend
benchmark-table/create/10k duration 904.70 (±8.90 ms) 878.30 (±6.20 ms) -26.4ms (2.9%) 👍
table-create-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table/create/1k duration 121.00 (±3.35 ms) 119.05 (±2.75 ms) -2.0ms (1.6%) 👍
table-update-10th-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table/update-10th/1k duration 71.60 (±1.60 ms) 71.10 (±2.55 ms) -0.5ms (0.7%) 👌
tablecmp-append-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/append/1k duration 225.50 (±10.65 ms) 228.20 (±10.20 ms) +2.7ms (1.2%) 👌
tablecmp-clear-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/clear/1k duration 5.80 (±1.00 ms) 6.45 (±1.25 ms) +0.6ms (11.2%) 👌
tablecmp-create-10k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/create/10k duration 1740.95 (±19.70 ms) 1748.15 (±15.20 ms) +7.2ms (0.4%) 👌
tablecmp-create-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/create/1k duration 209.60 (±4.80 ms) 211.55 (±7.90 ms) +1.9ms (0.9%) 👌
tablecmp-update-10th-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/update-10th/1k duration 69.05 (±5.80 ms) 69.55 (±4.20 ms) +0.5ms (0.7%) 👌
wc-append-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/append/1k duration 231.35 (±15.75 ms) 229.15 (±21.05 ms) -2.2ms (1.0%) 👌
wc-clear-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/clear/1k duration 10.95 (±1.80 ms) 10.70 (±1.80 ms) -0.3ms (2.3%) 👌
wc-create-10k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/create/10k duration 1858.10 (±13.75 ms) 1886.30 (±16.45 ms) +28.2ms (1.5%) 👎
wc-create-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/create/1k duration 217.90 (±6.45 ms) 219.60 (±5.60 ms) +1.7ms (0.8%) 👌
wc-update-10th-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/update-10th/1k duration 68.75 (±4.35 ms) 69.20 (±6.45 ms) +0.5ms (0.7%) 👌

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: c0776e4 | Target commit: a61a19a

lwc-engine-benchmark

table-append-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table/append/1k duration 155.85 (±4.30 ms) 154.25 (±5.50 ms) -1.6ms (1.0%) 👌
table-clear-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table/clear/1k duration 11.20 (±0.85 ms) 10.70 (±0.70 ms) -0.5ms (4.5%) 👌
table-create-10k metric base(c0776e4) target(a61a19a) trend
benchmark-table/create/10k duration 904.70 (±8.90 ms) 893.15 (±7.10 ms) -11.6ms (1.3%) 👍
table-create-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table/create/1k duration 121.00 (±3.35 ms) 119.10 (±2.80 ms) -1.9ms (1.6%) 👌
table-update-10th-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table/update-10th/1k duration 71.60 (±1.60 ms) 79.40 (±4.25 ms) +7.8ms (10.9%) 👎
tablecmp-append-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/append/1k duration 225.50 (±10.65 ms) 225.40 (±7.90 ms) -0.1ms (0.0%) 👌
tablecmp-clear-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/clear/1k duration 5.80 (±1.00 ms) 6.35 (±0.95 ms) +0.5ms (9.5%) 👌
tablecmp-create-10k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/create/10k duration 1740.95 (±19.70 ms) 1751.45 (±14.20 ms) +10.5ms (0.6%) 👌
tablecmp-create-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/create/1k duration 209.60 (±4.80 ms) 209.85 (±5.15 ms) +0.3ms (0.1%) 👌
tablecmp-update-10th-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-component/update-10th/1k duration 69.05 (±5.80 ms) 65.20 (±4.15 ms) -3.9ms (5.6%) 👌
wc-append-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/append/1k duration 231.35 (±15.75 ms) 235.70 (±15.45 ms) +4.3ms (1.9%) 👌
wc-clear-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/clear/1k duration 10.95 (±1.80 ms) 11.35 (±1.65 ms) +0.4ms (3.7%) 👌
wc-create-10k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/create/10k duration 1858.10 (±13.75 ms) 1883.40 (±23.40 ms) +25.3ms (1.4%) 👎
wc-create-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/create/1k duration 217.90 (±6.45 ms) 221.30 (±4.50 ms) +3.4ms (1.6%) 👌
wc-update-10th-1k metric base(c0776e4) target(a61a19a) trend
benchmark-table-wc/update-10th/1k duration 68.75 (±4.35 ms) 69.25 (±5.15 ms) +0.5ms (0.7%) 👌

@diervo diervo merged commit 4acd1d3 into master Mar 28, 2019
@diervo diervo deleted the dval/tsExtensionSupport branch March 28, 2019 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants