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

Extend the existing import-map when using htmlGenerate #117

Conversation

JayaKrishnaNamburu
Copy link
Member

No description provided.

@CLAassistant
Copy link

CLAassistant commented Mar 19, 2022

CLA assistant check
All committers have signed the CLA.

@JayaKrishnaNamburu
Copy link
Member Author

Extending the existing this.traceMap.map with the map from htmlGenerate. So, the htmlGenerate can be used for simple concatenation purposes.
Breaks a test right now, since it's inheriting the this.traceMap.map. I think we might need a clean-up action after generating map or some flag to allow this contactnation.

+ actual - expected ... Lines skipped

  '\n' +
    '<!doctype html>\n' +
...
    '  </script>\n' +
    '  <link rel="modulepreload" href="/react.js" />\n' +
+   '  <link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/cjs/react.production.min.js" />\n' +
    '  <link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/index.js" />\n' +
    '<script type="module">\n' +
    "  import 'react';\n" +
    '</script>\n'
    at file:///Users/jkrishna/Documents/jspm/generator/test/html/indent.test.js:13:8 {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: '\n' +
    '<!doctype html>\n' +
    '  <!-- Generated by @jspm/generator - https://github.com/jspm/generator -->\n' +
    '  <script async src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js" crossorigin="anonymous"></script>\n' +
    '  <script type="importmap">\n' +
    '  {\n' +
    '    "imports": {\n' +
    '      "object-assign": "/react.js",\n' +
    '      "react": "https://ga.jspm.io/npm:react@17.0.2/index.js"\n' +
    '    }\n' +
    '  }\n' +
    '  </script>\n' +
    '  <link rel="modulepreload" href="/react.js" />\n' +
    '  <link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/cjs/react.production.min.js" />\n' +
    '  <link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/index.js" />\n' +
    '<script type="module">\n' +
    "  import 'react';\n" +
    '</script>\n',
  expected: '\n' +
    '<!doctype html>\n' +
    '  <!-- Generated by @jspm/generator - https://github.com/jspm/generator -->\n' +
    '  <script async src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js" crossorigin="anonymous"></script>\n' +
    '  <script type="importmap">\n' +
    '  {\n' +
    '    "imports": {\n' +
    '      "object-assign": "/react.js",\n' +
    '      "react": "https://ga.jspm.io/npm:react@17.0.2/index.js"\n' +
    '    }\n' +
    '  }\n' +
    '  </script>\n' +
    '  <link rel="modulepreload" href="/react.js" />\n' +
    '  <link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/index.js" />\n' +
    '<script type="module">\n' +
    "  import 'react';\n" +
    '</script>\n',
  operator: 'strictEqual'
}

We can see a additional react tracing has been added to react

+   '  <link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/cjs/react.production.min.js" />\n' +

@guybedford
Copy link
Member

Can you please provide a test case that shows what this is solving in the first place?

@guybedford
Copy link
Member

Thanks for adding a test case... what exactly is the issue that the test case doesn't work on current generator? It seems like it should?

@JayaKrishnaNamburu
Copy link
Member Author

It works, but starting to break other tests. Before trying to fix them, I would like to know if this can be a valid use case to solve.

@guybedford
Copy link
Member

@JayaKrishnaNamburu I mean what is the issue that this PR solves? Looking at the test I can't tell why this test fails against the main branch.

@guybedford
Copy link
Member

@JayaKrishnaNamburu specifically I'm thinking here - I know of at least two bugs that might cause generation issues with versions and existing maps which I could fix, so knowing the test case and why it's failing in the first place would help to know if this is one of those bugs or indeed a new feature request.

@JayaKrishnaNamburu
Copy link
Member Author

It's the test from indent.test.js that's failing. I am not sure why. We are passing a simple html with module react used. But, it seems to generate two html tags for react. One with production and one with local. I don't know if i am able to explain correctly sorry 😅

<link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/cjs/react.production.min.js" />\n' +
'  <link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/index.js" />\n' +

It's adding two module preloads instead of just one. Where the import-map is just

 {
    "imports": {
      "object-assign": "/react.js"
    }
  }

@guybedford
Copy link
Member

It would really help for communication to always include a clear description and test when creating a PR to begin with.

I'm happy to help, I'm just very short on time. I'll take a look in the next couple of days.

@guybedford
Copy link
Member

Just cloned and ran this which was necessary to get the context, and I finally get the concept that you want to retain the existing map.

Is this because you have a set import map of possible packages that must be retained for dynamic imports that are untraceable by the generator?

If so, do you need to use the map as the source of truth or would it be possible to just rely on generator.install to prepopulate these packages?

@JayaKrishnaNamburu
Copy link
Member Author

I feel, replying on pre-defined import-map provided by the inputMap would be much reliable to eliminate the duplicate than the generator.install

@guybedford
Copy link
Member

I see, thanks, yes I agree inputMap should be authoritatively embedded without pruning.

So the reason for the test failures then is that they share the generator instance, and thus this.traceMap.map has contents from the previous run.

Let's rather store inputMap in the constructor of the Generator on the instance, and extend from that directly rather than using this.traceMap.map as the inputMap source.

@JayaKrishnaNamburu
Copy link
Member Author

So the reason for the test failures then is that they share the generator instance, and thus this.traceMap.map has contents from the previous run.

Yes, exactly what i was trying to say before 😅

@guybedford
Copy link
Member

Yes, exactly what i was trying to say before

I see, but you did not mention inputMap or provide an initial description which did, which was why it took me so long to follow and required me to clone the repo and actually work through the code in detail to follow it.

@guybedford
Copy link
Member

This should now be fully supported by #134.

@guybedford guybedford closed this Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants