question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Official, gradual path to RN packages not publishing untranspiled code

See original GitHub issue

The current practice in the RN community for package authors is to publish untranspiled code, to npmignore babelrc, and for the RNP to transpile node_modules.

While this may work great for the RN community, this defies many best practices in the wider node/npm/JS community:

  • package.json’s “main” only points to ES5 commonJS
  • npm explore foo && npm install && npm test should work (note this isn’t universal, but it’s frustrating to be asked to npmignore .babelrc and break this use case due to the RNP)

In addition, this practice kind of permanently cements RN packages with the transpiler settings that the RNP uses - which, since it includes not-yet-stage-4 features, are quite likely to change in a breaking way in the future.

Here’s my proposal to enable the benefits of the current approach (cleaner stack traces, optimization opportunities within the RNP, etc) in a way that will allow RN packages to rejoin the wider JS ecosystem:

  1. Designate a new top-level package.json key - let’s go with “sources” for the time being. This contains an object. All subkeys of “sources” are optional.
  2. Within “sources”:
  3. “raw” points to the entry point for utterly untranspiled code. .babelrc (or other babel config locations), if provided, configure how this code should be transformed.
  4. “react-native-v1” (swap out v1 for any versioning scheme; this frees up the RNP to change their preferred transpiler settings freely.
  5. “node4”, “node5”, “node6”, “node7”, etc: code transpiled down to features matching the indicated major node version, following https://www.npmjs.com/package/babel-preset-node7, https://www.npmjs.com/package/babel-preset-node6, etc.
  6. “es2015”, “es2016”, etc: code transpiled down to features that are included in the given year of publication of the ecmascript standard.
  7. The RNP ships with support for this, with priority: [“react-native-", "node-” (>= the major node version, obv), “main” (with transpiling)]. This change is loudly communicated with blogs, tweets, and documentation.
  8. At some future point (this can be as soon, or as indefinite, as is deemed necessary), the RNP will cease transpiling “main” - since the other “sources” don’t require looking for babel configs, this will be when RN packages can (and should) publish their .babelrcs again.

This approach allows for supporting other languages, future transpiler settings, etc, in a nonbreaking way, without infecting the npm ecosystem with untranspiled “main” entry points (inhibiting people’s ability to share RN packages across normal react). A package will always be able to choose to omit “main” entirely, which will clearly and explicitly convey to users that their package must not be used without the RNP.

Further reading (credit @ide): https://gist.github.com/ide/e7b9181984933ebb0755c7367a32e7e8

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:19
  • Comments:28 (18 by maintainers)

github_iconTop GitHub Comments

6reactions
hramoscommented, May 25, 2017

In the process of closing stale issues, I missed that @ljharb was the original author of this issue. I think it’s fair to re-open an issue where the OP is actively interested.

I’ll re-open this for now, so we don’t lose track of it when the packager is moved out.

5reactions
quantuminformationcommented, Mar 8, 2018

No supper for stalebot tonight.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Package is not publishing to npm (not in the npm registry)
Try npm login . In case of npm publish , sometimes misleading message is shown.
Read more >
Applicant Frequently Asked Questions
How do I become a Registered Nurse (RN) in California? For detailed information, please visit our Nursing Careers page. What is the Fingerprint...
Read more >
View the Code of Ethics for Nurses | ANA Enterprise
The Code of Ethics for Nurses with Interpretive Statements (The Code) was developed as a guide for carrying out nursing responsibilities in a...
Read more >
Alabama Board of Nursing
You Must Have Adequate CE: The ABN Administrative Code requires Alabama nurses to complete 24 hours of continuing education (CE) credit per license...
Read more >
Ohio Board of Nursing | Ohio.gov
An Ohio.gov website belongs to an official government organization in the State of Ohio. Secure .gov websites use HTTPS. A lock or https://...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found