Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add preserveModulesRoot config option (#3786)
* add initial moduleRootDir implementation * moduleRootDir -> preserveModulesRoot Also avoid regex, switch `path.resolve` to `path.join` due to lack of browser support for `path.join` * update cli help + docs * fix optionList test * add preserveModulesRoot test * fix preserveModulesRootDir -> preserveModulesRoot * fix preserveModulesRootDir -> preserveModulesRoot * Fix cli help styling * Refactor code * early return -> path =
- Loading branch information
1 parent
bb4d3a7
commit f6b14ef
Showing
33 changed files
with
344 additions
and
16 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 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 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 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
21 changes: 21 additions & 0 deletions
21
test/chunking-form/samples/preserve-modules-root/_config.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,21 @@ | ||
const commonjs = require('@rollup/plugin-commonjs'); | ||
const resolve = require('@rollup/plugin-node-resolve').default; | ||
|
||
module.exports = { | ||
description: 'confirm preserveModulesRoot restructures src appropriately', | ||
options: { | ||
input: ['src/under-build.js', 'src/below/module.js'], | ||
plugins: [ | ||
resolve({ | ||
customResolveOptions: { | ||
moduleDirectory: ['custom_modules'] | ||
} | ||
}), | ||
commonjs() | ||
], | ||
output: { | ||
preserveModules: true, | ||
preserveModulesRoot: 'src' | ||
} | ||
} | ||
}; |
22 changes: 22 additions & 0 deletions
22
test/chunking-form/samples/preserve-modules-root/_expected/amd/_virtual/_commonjsHelpers.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,22 @@ | ||
define(['exports'], function (exports) { 'use strict'; | ||
|
||
function createCommonjsModule(fn, basedir, module) { | ||
return module = { | ||
path: basedir, | ||
exports: {}, | ||
require: function (path, base) { | ||
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); | ||
} | ||
}, fn(module, module.exports), module.exports; | ||
} | ||
|
||
function commonjsRequire () { | ||
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); | ||
} | ||
|
||
exports.commonjsRequire = commonjsRequire; | ||
exports.createCommonjsModule = createCommonjsModule; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}); |
7 changes: 7 additions & 0 deletions
7
...hunking-form/samples/preserve-modules-root/_expected/amd/_virtual/index.js_commonjs-proxy
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 @@ | ||
define(['../custom_modules/@my-scope/my-base-pkg/index'], function (index) { 'use strict'; | ||
|
||
|
||
|
||
return index.myBasePkg; | ||
|
||
}); |
9 changes: 9 additions & 0 deletions
9
test/chunking-form/samples/preserve-modules-root/_expected/amd/below/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,9 @@ | ||
define(['../custom_modules/@my-scope/my-base-pkg/index'], function (index) { 'use strict'; | ||
|
||
var module = { | ||
base2: index.myBasePkg, | ||
}; | ||
|
||
return module; | ||
|
||
}); |
16 changes: 16 additions & 0 deletions
16
...samples/preserve-modules-root/_expected/amd/custom_modules/@my-scope/my-base-pkg/index.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,16 @@ | ||
define(['exports', '../../../_virtual/_commonjsHelpers'], function (exports, _commonjsHelpers) { 'use strict'; | ||
|
||
var myBasePkg = _commonjsHelpers.createCommonjsModule(function (module, exports) { | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
var hello = 'world'; | ||
|
||
exports.hello = hello; | ||
}); | ||
|
||
exports.myBasePkg = myBasePkg; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}); |
9 changes: 9 additions & 0 deletions
9
test/chunking-form/samples/preserve-modules-root/_expected/amd/under-build.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,9 @@ | ||
define(['./custom_modules/@my-scope/my-base-pkg/index'], function (index) { 'use strict'; | ||
|
||
var underBuild = { | ||
base: index.myBasePkg | ||
}; | ||
|
||
return underBuild; | ||
|
||
}); |
20 changes: 20 additions & 0 deletions
20
test/chunking-form/samples/preserve-modules-root/_expected/cjs/_virtual/_commonjsHelpers.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,20 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
function createCommonjsModule(fn, basedir, module) { | ||
return module = { | ||
path: basedir, | ||
exports: {}, | ||
require: function (path, base) { | ||
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); | ||
} | ||
}, fn(module, module.exports), module.exports; | ||
} | ||
|
||
function commonjsRequire () { | ||
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); | ||
} | ||
|
||
exports.commonjsRequire = commonjsRequire; | ||
exports.createCommonjsModule = createCommonjsModule; |
7 changes: 7 additions & 0 deletions
7
...hunking-form/samples/preserve-modules-root/_expected/cjs/_virtual/index.js_commonjs-proxy
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 @@ | ||
'use strict'; | ||
|
||
var index = require('../custom_modules/@my-scope/my-base-pkg/index.js'); | ||
|
||
|
||
|
||
module.exports = index.myBasePkg; |
9 changes: 9 additions & 0 deletions
9
test/chunking-form/samples/preserve-modules-root/_expected/cjs/below/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,9 @@ | ||
'use strict'; | ||
|
||
var index = require('../custom_modules/@my-scope/my-base-pkg/index.js'); | ||
|
||
var module$1 = { | ||
base2: index.myBasePkg, | ||
}; | ||
|
||
module.exports = module$1; |
16 changes: 16 additions & 0 deletions
16
...samples/preserve-modules-root/_expected/cjs/custom_modules/@my-scope/my-base-pkg/index.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,16 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
var _commonjsHelpers = require('../../../_virtual/_commonjsHelpers.js'); | ||
|
||
var myBasePkg = _commonjsHelpers.createCommonjsModule(function (module, exports) { | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
var hello = 'world'; | ||
|
||
exports.hello = hello; | ||
}); | ||
|
||
exports.myBasePkg = myBasePkg; |
9 changes: 9 additions & 0 deletions
9
test/chunking-form/samples/preserve-modules-root/_expected/cjs/under-build.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,9 @@ | ||
'use strict'; | ||
|
||
var index = require('./custom_modules/@my-scope/my-base-pkg/index.js'); | ||
|
||
var underBuild = { | ||
base: index.myBasePkg | ||
}; | ||
|
||
module.exports = underBuild; |
15 changes: 15 additions & 0 deletions
15
test/chunking-form/samples/preserve-modules-root/_expected/es/_virtual/_commonjsHelpers.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,15 @@ | ||
function createCommonjsModule(fn, basedir, module) { | ||
return module = { | ||
path: basedir, | ||
exports: {}, | ||
require: function (path, base) { | ||
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); | ||
} | ||
}, fn(module, module.exports), module.exports; | ||
} | ||
|
||
function commonjsRequire () { | ||
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); | ||
} | ||
|
||
export { commonjsRequire, createCommonjsModule }; |
2 changes: 2 additions & 0 deletions
2
...chunking-form/samples/preserve-modules-root/_expected/es/_virtual/index.js_commonjs-proxy
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,2 @@ | ||
import { m as myBasePkg } from '../custom_modules/@my-scope/my-base-pkg/index.js'; | ||
export { m as default } from '../custom_modules/@my-scope/my-base-pkg/index.js'; |
7 changes: 7 additions & 0 deletions
7
test/chunking-form/samples/preserve-modules-root/_expected/es/below/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,7 @@ | ||
import { m as myBasePkg } from '../custom_modules/@my-scope/my-base-pkg/index.js'; | ||
|
||
var module = { | ||
base2: myBasePkg, | ||
}; | ||
|
||
export default module; |
12 changes: 12 additions & 0 deletions
12
.../samples/preserve-modules-root/_expected/es/custom_modules/@my-scope/my-base-pkg/index.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,12 @@ | ||
import { createCommonjsModule } from '../../../_virtual/_commonjsHelpers.js'; | ||
|
||
var myBasePkg = createCommonjsModule(function (module, exports) { | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
var hello = 'world'; | ||
|
||
exports.hello = hello; | ||
}); | ||
|
||
export { myBasePkg as m }; |
7 changes: 7 additions & 0 deletions
7
test/chunking-form/samples/preserve-modules-root/_expected/es/under-build.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,7 @@ | ||
import { m as myBasePkg } from './custom_modules/@my-scope/my-base-pkg/index.js'; | ||
|
||
var underBuild = { | ||
base: myBasePkg | ||
}; | ||
|
||
export default underBuild; |
27 changes: 27 additions & 0 deletions
27
...chunking-form/samples/preserve-modules-root/_expected/system/_virtual/_commonjsHelpers.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,27 @@ | ||
System.register([], function (exports) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
exports({ | ||
commonjsRequire: commonjsRequire, | ||
createCommonjsModule: createCommonjsModule | ||
}); | ||
|
||
function createCommonjsModule(fn, basedir, module) { | ||
return module = { | ||
path: basedir, | ||
exports: {}, | ||
require: function (path, base) { | ||
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); | ||
} | ||
}, fn(module, module.exports), module.exports; | ||
} | ||
|
||
function commonjsRequire () { | ||
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); | ||
} | ||
|
||
} | ||
}; | ||
}); |
15 changes: 15 additions & 0 deletions
15
...king-form/samples/preserve-modules-root/_expected/system/_virtual/index.js_commonjs-proxy
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,15 @@ | ||
System.register(['../custom_modules/@my-scope/my-base-pkg/index.js'], function (exports) { | ||
'use strict'; | ||
var myBasePkg; | ||
return { | ||
setters: [function (module) { | ||
myBasePkg = module.m; | ||
exports('default', module.m); | ||
}], | ||
execute: function () { | ||
|
||
|
||
|
||
} | ||
}; | ||
}); |
16 changes: 16 additions & 0 deletions
16
test/chunking-form/samples/preserve-modules-root/_expected/system/below/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,16 @@ | ||
System.register(['../custom_modules/@my-scope/my-base-pkg/index.js'], function (exports) { | ||
'use strict'; | ||
var myBasePkg; | ||
return { | ||
setters: [function (module) { | ||
myBasePkg = module.m; | ||
}], | ||
execute: function () { | ||
|
||
var module$1 = exports('default', { | ||
base2: myBasePkg, | ||
}); | ||
|
||
} | ||
}; | ||
}); |
Oops, something went wrong.