-
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
Conversation
This package is ESM-only now and requires additional changes to how it's imported and used |
… to commonjs right now
28b0fcf
to
66dd212
Compare
presets: [["babel-preset-gatsby-package"]], | ||
presets: [["babel-preset-gatsby-package", { | ||
keepDynamicImports: [`./src/utils/feedback.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.
this PR adds a way to mark individual files to not transform
await import("")
to
await Promise.resolve().then(() => _interopRequireWildcard(require("")));
and instead keep dynamic import
We have plenty of dynamic imports in our codebase / gatsby
package and switching it everywhere (through already existing esm: true
option that babel-preset-gatsby-package
) doesn't seem like good idea and definitely would require solid testing.
This approach allows us to address individual modules and we can over-time migrate more things if needed
[path.resolve(__dirname, "../../babel-transform-compiler-flags.js"), | ||
[path.resolve(__dirname, "../../../babel-transform-compiler-flags.js"), |
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
ensuring default doesn't change to not introduce accidental regressions
exports.someFunction2 = someFunction2; | ||
|
||
async function someFunction2() { | ||
return await import(`path`); |
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 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
[path.resolve(__dirname, "../../../index.js"), | |
{ | |
keepDynamicImports: [`./packages/babel-preset-gatsby-package/lib/__tests__/fixtures/keep-dynamic-import/with-override/input.js`] | |
} | |
], | |
], |
Description
This updates to latest of ...
latest-version
- this package requiresnode@>=14.16
, which we couldn't do in v4 due to us being on minimalnode@14.15
Related Issues
[ch54713]