jspm / jspm-cli

ES Module Package Manager
https://jspm.org
Apache License 2.0
3.77k stars 274 forks source link

feat: add `integrity` flag support #2571

Closed guybedford closed 2 months ago

guybedford commented 2 months ago

Updates to the latest generator.

JayaKrishnaNamburu commented 2 months ago

@guybedford i started looking into this, and the tests are failing from the usage of @babel/core. We get @babel/core@7.24 now from the @jspm/generator. So during the check for type of file. The tests are failing now. Which is here

const source = await fs.readFile(resolvedModule.target, { encoding: "utf8" });
  const babel = await import("@babel/core");

  try {
    babel.parse(source);
    return resolvedModule; // this is a javascript module, it parsed correctly
  } catch (e) {
    /* fallback to parsing it as html */
  }

https://github.com/jspm/jspm-cli/blob/main/src/link.ts#L130

But seems there is no default exports in node env. https://codesandbox.io/p/devbox/elated-saha-qw6s77?file=%2Fpackage.json%3A11%2C49

It passes if its changed to named-import here. But then the tracer from @jspm/generator again uses the same approach and the tests fail.

export async function createCjsAnalysis(
  imports: any,
  source: string,
  url: string
): Promise<Analysis> {
  if (!babel) ({ default: babel } = await import("@babel/core"));

  const requires = new Set<string>();
  const lazy = new Set<string>();
  const unboundGlobals = new Set<string>();

  babel.transform(source, {
    ast: false,
    sourceMaps: false,

https://github.com/jspm/generator/blob/main/src/trace/cjs.ts#L24

The one from the generators seems to pass because the project is built using rollup there. And i suspect the behaviour in both the places is little different. Should we switch to named-imports in both the places. Any inputs fro this ?

And btw, the import for @babel/core also seems to fail with import-map now. https://jspm.org/sandbox#H4sIAAAAAAAAA6VZbXPTOBD+zq8Q4QvcVLaTttAraSfAdJiDhruhlLv7qNhyrFa2jCQnpDf891vJL4mN49jlQ14s7T7PanclreTp00D4epNSFOmYXz6Zlj+UBJdPEJrGVBPkR0Qqqi9GmQ7x2ch2aKY5vWRxKqSOSYrvVBrjmGgqGeE4Y1M3l6hAEhLTi9GK0bVRGSFfJJomALpmgY4uArpiPsX24QixhGmDo3zC6cUYKKdubtN0IYKNRX2KMfwg9OHmrzl6TxMqiRYS/WFNQnOS2t6rgGl0+/n6HEaoU3XuustS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K4E7EpbMPntSIHdJF1zS7bD1lkFkgl/T3HV8rhICrNoUNgP5IiZlnsmn0BtvSucLfp2SXjbHxW6Te5lE9SWhZLki6hWOuiaBG3mXXa6o+wc3c6OCHCprWQp2qTdK2ehYS1ycMLqsme9FxysSC8y75CYjaGTJrsCfidAmff086wVDIQ+H2Jc6fAs50Y0A9uOoXR2P8NfS4z7BM/6poblczsFKZG+yrWeZiB88rEbrRtmiZ4kBCcEjDPza8NpDBnDhq4cJg1oewsZWsAeUac7MU5TF48YQUDNqeunxoeb08/6IaJKdHRL00GA9DEZL6wK15X1LZCdlKM3W2D077+FP7+NWtzDAy/QWZvFBokisarzv0yF5i9dMyOmz80IbLUHt+xHU0XVE0Q0v8UpmH72GHpDInSxm446mjWWcD8LNyxN2wIP1BqFBK2mh27xVN1d43Qjyflt/lM3fw23VyeFy8A0NUNmts7BnQTsVidl9f/sGsplAq+CRnnKBQSCR5QicriBq2ZjkSmEduRL7yGntMluiEhkQyNIRovitv88jKfmPUWwW52sX/TKG8+lLHK7MxeebPa6DOjRb4USgnJliy5gFJSJJtYZGp02Rxx7W1CjmJfJaByGL+BcegdZCkKYTesv0l4nYMg5LrobwkFEgyaJSiHQaakRhGV9AiBswCFIEVTc3sBWAwEjMOgcQTjHiGiYT9cZNAnEqQjWqLkBjqWBuoIOJhQh4vlc2PSi9e1GE7d/E3O1M3fOf0Pp+3wYIsaAAA=

guybedford commented 2 months ago

@JayaKrishnaNamburu thanks for looking into this. I've pushed a fix for Babel, is it working now for you? You may need to clear your browser cache.

JayaKrishnaNamburu commented 2 months ago

@guybedford the fix for jspm is working good now. Should we switch to namedImports for @babel/core in generator and in the cli. Because the direct import of @babel/core is missing the default export from the package in node env.

guybedford commented 2 months ago

Yes, let's update the generator to use named exports now then?

JayaKrishnaNamburu commented 2 months ago

cool, will update the PR here and make on on the generator for the same 👍

guybedford commented 2 months ago

Let me know if I can help further on this PR at all.