BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.88k stars 427 forks source link

Generated sub-module names are invalid #280

Open asos-craigmorten opened 1 year ago

asos-craigmorten commented 1 year ago

Describe the bug

I am using tooling which analyses application dependencies, utilising the likes of normalize-package-data.

This has uncovered that the "generated" names used for sub-modules of the @builder.io/partytown module, e.g. for React, have seemingly "invalid" package names such as @builder.io/partytown/react owing to them including an additional / beyond that to delimit the scope from the package name.

This violates the restriction on package names needing to be "URL safe" and thus tooling in userland will reject this name as invalid - see https://github.com/npm/normalize-package-data/issues/163.

Given these sub-modules aren't actually published to NPM the restrictions on the name(s) is somewhat moot as Partytown functions as intended in isolation. It would be grand if changes could be considered nevertheless to aid it's integration with the wider userland ecosystem.

For example, if it is workable(!) it seems the package name as defined in the repo is valid so this could perhaps be used - haven't dug into it yet but presume somewhere in the build process the package name is being overwritten with a generated value matching the directory structure.

To Reproduce

Steps to reproduce the behavior:

  1. Create a new project:

    mkdir repro
    cd repro
    npm init
    npm install @builder.io/partytown
  2. Read the contents of the Partytown sub-dependencies, e.g.

    $ cat ./node_modules/@builder.io/partytown/react/package.json
    
    {
      "name": "@builder.io/partytown/react",
      "main": "index.cjs",
      "module": "index.mjs",
      "types": "index.d.ts",
      "version": "0.7.1",
      "private": true
    }
  3. Observe that the package name(s) violate the "URL safe" NPM restrictions on package names in including a / other than for delimiting the scope.

Reproduction link

https://codesandbox.io/s/partytown-sub-module-name-issue-j7kjy8

Expected behavior

Package names (generated or static) for all Partytown modules (top level or sub) adhere to NPM package name requirements.

E.g. using the names currently in the repo's source code rather than the generated directory path names when published: @builder.io/partytown/react -> @builder.io/partytown-react.

Partytown version

0.7.1

Screenshots

VSCode with the `@builder.io/partytown` `react` directory open in the `node_modules` directory, with the `package.json` file open in a tab showing the invalid package name.

Additional context

Raising off back of https://github.com/npm/normalize-package-data/issues/163.

asos-craigmorten commented 1 year ago

Example pertinent code: https://github.com/BuilderIO/partytown/blob/main/scripts/build-react.ts#L22