-
Notifications
You must be signed in to change notification settings - Fork 400
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
Conversation
This comment has been minimized.
This comment has been minimized.
|
||
export default function nodeModulesPaths( | ||
basedir: string, | ||
{ moduleDirectory }: NodeModulesConfig = {} |
There was a problem hiding this comment.
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.
{ moduleDirectory }: NodeModulesConfig = {} | |
{ moduleDirectory }: NodeModulesConfig |
@@ -97,13 +112,12 @@ function resolveModules(modules, opts) { | |||
} | |||
} | |||
|
|||
function resolveLwcNpmModules(options = {}) { | |||
function resolveLwcNpmModules(options: ModuleResolverConfig = {}) { |
There was a problem hiding this comment.
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.
function resolveLwcNpmModules(options: ModuleResolverConfig = {}) { | |
export function resolveLwcNpmModules(options: ModuleResolverConfig = {}) { |
@@ -97,13 +112,12 @@ function resolveModules(modules, opts) { | |||
} | |||
} | |||
|
|||
function resolveLwcNpmModules(options = {}) { | |||
function resolveLwcNpmModules(options: ModuleResolverConfig = {}) { |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
@diervo Since the compiler doesn't provide pre-processor hooks to run |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Benchmark resultsBase commit: lwc-engine-benchmark
|
There was a problem hiding this 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); |
There was a problem hiding this comment.
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'), |
There was a problem hiding this comment.
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.
…nto dval/tsExtensionSupport
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
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.