Skip to content
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

fix: add regenerate-unicode-properties to dynamicRequireTargets #12819

Merged
merged 4 commits into from Feb 20, 2021

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Feb 18, 2021

Q                       A
Fixed Issues? Fixes #12815, closes babel/website#2426
Patch: Bug Fix? Y
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The confusing error unknown L is thrown because Rollup complains regenerate-unicode-properties should be added to dynamicRequireTargets, which is then caught in

https://github.com/mathiasbynens/regexpu-core/blob/ffd8fff2e31f4597f6fdfee75d5ac1c5c8111ec3/rewrite-pattern.js#L64

resulting to a complete different error message.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: standalone labels Feb 18, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 18, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit eb907f0:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

Gulpfile.mjs Outdated
@@ -292,6 +292,10 @@ function buildRollup(packages, targetBrowsers) {
"packages/babel-compat-data/*.js",
"packages/*/src/**/*.cjs",
],
dynamicRequireTargets: [
// https://github.com/mathiasbynens/regexpu-core/blob/ffd8fff2e31f4597f6fdfee75d5ac1c5c8111ec3/rewrite-pattern.js#L48
"node_modules/regenerate-unicode-properties/**",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not guaranteed that it's always inside the top-level node_modules, since it's a nested dependency.

WDYT about creating a utility like this?

import { createRequire } from "module";
import { fileURLToPath } from "url";
import { dirname } from "path";

/**
 * Resolve a nested dependency starting from the given file
 */
export default function resolveChain(baseUrl, ...packages) {
  const require = createRequire(baseUrl);

  return packages.reduce(
    (base, pkg) => require.resolve(pkg, { paths: [dirname(base)] }),
    fileURLToPath(baseUrl)
  );
}

And then we can use

resolveChain(
  import.meta.url,
  "packages/babel-helper-create-regexp-features-plugin",
  "regexpu-core",
  "regenerate-unicode-properties"
);

Also, maybe we can end the pattern with **/*.js to only include JS files?

Copy link
Contributor Author

@JLHwung JLHwung Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That looks fancy! I think it is okay to use **/*. If we have require("foo/bar.md"), rollup will throw when bundling bar.md.

I think resolveChain will break if a package switch main from index.js to lib/index.js since we are meant to match all files within this package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use regenerate-unicode-properties/package.json as the last param to avoid that breakage.

@babel-bot
Copy link
Collaborator

babel-bot commented Feb 18, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/41157/

@JLHwung
Copy link
Contributor Author

JLHwung commented Feb 18, 2021

The e2e error is fixed in #12821 , will rebase once that one gets merged.

Gulpfile.mjs Outdated Show resolved Hide resolved
Gulpfile.mjs Outdated Show resolved Hide resolved
@nicolo-ribaudo nicolo-ribaudo merged commit 72961e4 into babel:main Feb 20, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the fix-12815 branch February 20, 2021 19:05
@nicolo-ribaudo
Copy link
Member

This seems to work locally because it delegates to Node's require(), but it still fails in a browser.

This was referenced Mar 12, 2021
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 23, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: standalone PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unicode property “L” in regular expression broke recently You can't compile /\p{L}/u regex in playground
4 participants