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: add option to keep extensions for amd #4607
Changes from 5 commits
b543795
b331d2d
913312a
4289689
f3a1d0a
d27fd4e
a412009
4427349
22a6dfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function addJsExtension(name: string): string { | ||
return !name.endsWith('.js') ? name + '.js' : name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You added a new logic here, was this intended? E.g. if you have an external dependency There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extension depends on for example: import foo from './foo';
import bar from 'bar'; ( define(['./foo.js', 'bar'], function (foo, bar) {}) ( define(['./foo', 'bar'], function (foo, bar) {}) It partially tested in this commit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah I see, the case that is not tested (and which coverage complains about) is not what I thought but actually the combination relative id + js extension present + keep extension. Maybe you can add this for coverage. The problem I saw is that But then again, they should not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it should be
I do not quite understand what is at stake. If you talking about dependencies in
No, if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is an even better name |
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import addJsExtension from './addJsExtension'; | ||
import removeJsExtension from './removeJsExtension'; | ||
|
||
// AMD resolution will only respect the AMD baseUrl if the .js extension is omitted. | ||
// The assumption is that this makes sense for all relative ids: | ||
// https://requirejs.org/docs/api.html#jsfiles | ||
export default function updateExtensionForRelativeAmdId( | ||
id: string, | ||
keepExtension: boolean | ||
): string { | ||
if (id[0] !== '.') { | ||
return id; | ||
} | ||
|
||
return keepExtension ? addJsExtension(id) : removeJsExtension(id); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
description: 'keep extension for AMD modules', | ||
options: { | ||
external: ['./foo', 'baz/quux'], | ||
output: { interop: 'default', amd: { keepExtension: true } } | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
define(['./foo.js', 'baz/quux'], (function (foo, baz) { 'use strict'; | ||
|
||
const bar = 42; | ||
|
||
console.log(foo, bar, baz); | ||
|
||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
var foo = require('./foo'); | ||
var baz = require('baz/quux'); | ||
|
||
const bar = 42; | ||
|
||
console.log(foo, bar, baz); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import foo from './foo'; | ||
import baz from 'baz/quux'; | ||
|
||
const bar = 42; | ||
|
||
console.log(foo, bar, baz); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(function (foo, baz) { | ||
'use strict'; | ||
|
||
const bar = 42; | ||
|
||
console.log(foo, bar, baz); | ||
|
||
})(foo, baz); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
System.register(['./foo', 'baz/quux'], (function () { | ||
'use strict'; | ||
var foo, baz; | ||
return { | ||
setters: [function (module) { | ||
foo = module["default"]; | ||
}, function (module) { | ||
baz = module["default"]; | ||
}], | ||
execute: (function () { | ||
|
||
const bar = 42; | ||
|
||
console.log(foo, bar, baz); | ||
|
||
}) | ||
}; | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('./foo'), require('baz/quux')) : | ||
typeof define === 'function' && define.amd ? define(['./foo.js', 'baz/quux'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.foo, global.baz)); | ||
})(this, (function (foo, baz) { 'use strict'; | ||
|
||
const bar = 42; | ||
|
||
console.log(foo, bar, baz); | ||
|
||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const bar = 42; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import foo from './foo'; | ||
import { bar } from './bar'; | ||
import baz from 'baz/quux'; | ||
|
||
console.log(foo, bar, baz); |
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.
This file should wrap at 80 characters, can we slightly shorten this? E.g. "Add
.js
extension in imports"