-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
chore(gatsby): upgrade latest-version #36434
Changes from 7 commits
1b367c0
0d5c926
2215c65
66dd212
2dc7748
2aefe78
906e491
05a177e
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 async function someFunction() { | ||
return await import(`path`); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
|
||
exports.__esModule = true; | ||
exports.someFunction = someFunction; | ||
|
||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
|
||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
|
||
async function someFunction() { | ||
return await Promise.resolve().then(() => _interopRequireWildcard(require(`path`))); | ||
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. ensuring default doesn't change to not introduce accidental regressions |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const path = require("path") | ||
|
||
// "babel-plugin-dynamic-import-node" is used in tests, so we force not a test environment | ||
process.env.BABEL_ENV = `not-a-test` | ||
|
||
module.exports = { | ||
sourceType: "module", | ||
presets: [ | ||
[path.resolve(__dirname, "../../../index.js"), | ||
{ | ||
keepDynamicImports: [`./packages/babel-preset-gatsby-package/lib/__tests__/fixtures/keep-dynamic-import/with-override/input.js`] | ||
} | ||
], | ||
], | ||
babelrc: false, | ||
configFile: false, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function someFunction2() { | ||
return await import(`path`); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||||||||||
"use strict"; | ||||||||||||||
|
||||||||||||||
exports.__esModule = true; | ||||||||||||||
exports.someFunction2 = someFunction2; | ||||||||||||||
|
||||||||||||||
async function someFunction2() { | ||||||||||||||
return await import(`path`); | ||||||||||||||
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. this file was marked to keep dynamic import in gatsby/packages/babel-preset-gatsby-package/lib/__tests__/fixtures/keep-dynamic-import/options.js Lines 9 to 14 in 906e491
|
||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
const runner = require(`@babel/helper-plugin-test-runner`).default | ||
|
||
runner(__dirname) | ||
// runner(__dirname + `/compiler-flags`) | ||
runner(__dirname ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const path = require(`path`) | ||
|
||
/** | ||
* @typedef {import('@babel/core').NodePath} NodePath | ||
* @typedef {import('@babel/core').PluginObj} PluginObj | ||
* @typedef {import('@babel/core').PluginPass} PluginPass | ||
* @typedef {import('@babel/core').types} BabelTypes | ||
* @typedef {import('@babel/core').types.Identifier} Identifier | ||
* @typedef {import('@babel/core').types.MemberExpression} MemberExpression | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} IPluginOptions | ||
* @property {Array<string>} keepDynamicImports | ||
*/ | ||
|
||
/** | ||
* | ||
* @param {{ types: BabelTypes }} _unused | ||
* @param {Partial<IPluginOptions>} opts | ||
* @returns {PluginObj} | ||
*/ | ||
module.exports = function keepDynamicImports( | ||
_unused, | ||
opts | ||
) { | ||
if (!opts.keepDynamicImports) { | ||
throw new Error(`keepDynamicImports option needs to be set`) | ||
} else if (!Array.isArray(opts.keepDynamicImports)) { | ||
throw new Error(`keepDynamicImports option needs to be an array`) | ||
} | ||
|
||
const absolutePaths = opts.keepDynamicImports.map(p => path.resolve(p)) | ||
|
||
return { | ||
name: `babel-transform-mark-to-keep-dynamic-import`, | ||
visitor: { | ||
Program() { | ||
const filename = this.file?.opts?.filename | ||
if (!filename) { | ||
return | ||
} | ||
|
||
if (absolutePaths.includes(filename)) { | ||
// this is big hack - it relies on some babel plugins internal to basically | ||
// do early return ( https://github.com/babel/babel/blob/3526b79c87863052f1c61ec0c49c0fc287ba32e6/packages/babel-plugin-transform-modules-commonjs/src/index.ts#L174 ) | ||
// on top of that `BabelFile` doesn't expose delete for the metadata, | ||
// so we reach into internal `_map` to delete it | ||
this.file._map.delete("@babel/plugin-proposal-dynamic-import") | ||
} | ||
} | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,7 @@ | |
// Ref: https://github.com/babel/babel/pull/7358 | ||
module.exports = { | ||
sourceMaps: true, | ||
presets: [["babel-preset-gatsby-package"]], | ||
presets: [["babel-preset-gatsby-package", { | ||
keepDynamicImports: [`./src/utils/feedback.ts`] | ||
}]], | ||
Comment on lines
-6
to
+8
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. this PR adds a way to mark individual files to not transform
to
and instead keep dynamic import We have plenty of dynamic imports in our codebase / This approach allows us to address individual modules and we can over-time migrate more things if needed |
||
} |
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 was moved from top-level for all fixtures to one directory below that, hence path adjustment