mizchi / uniroll

Opinionated universal frontend bundler in browser
https://focused-raman-3ce115.netlify.com/
113 stars 5 forks source link

babel-plugin-transform-import-to-skypack-cdn ignore scoped modules' version #11

Closed azu closed 3 years ago

azu commented 4 years ago

babel-plugin-transform-import-to-skypack-cdn just ignore the version of scoped modules.

For example, @textlint/kernel will be resolved as @textlint/kernel@3.3.2. But, babel-plugin-transform-import-to-skypack-cdn ignore the version.

require("isomorphic-unfetch");
const fs = require("fs");
const path = require("path");
const { compile } = require("uniroll");
const files = {
    "/package.json": `{
  "dependencies": {
    "@textlint/kernel": "3.3.2",
    "@textlint/textlint-plugin-markdown": "5.1.12",
    "textlint-rule-no-todo": "2.0.1"
  }
}`,
    "/index.js": `
import { TextlintKernel } from "@textlint/kernel";
import markdown from "@textlint/textlint-plugin-markdown";
import rule from "textlint-rule-no-todo";
const textlint = new TextlintKernel();
textlint.lintText("- [ ] No TODO ", {
    filePath: "/path/to/README.md",
    ext: ".md",
    plugins: [
        {
            pluginId: "markdown",
            plugin: markdown
        }
    ],
    rules: [{
        ruleId: "textlint-rule-no-todo",
        rule: rule,
        options: {}
    }]
}).then(result => {
    console.log("Output:");
    console.log(JSON.stringify(result, null, 4));
}).catch(error => {
    console.error(error);
});

 `
};
(async () => {
    const bundle = await compile({
        useInMemory: true,
        files,
        input: "/index.js"
    });
    // return rollup object
    const out = await bundle.generate({});
    for (const i of out.output) {
        if (i.type === "chunk") {
            const outpath = path.join(process.cwd(),  "out.js");
            fs.writeFileSync(outpath, i.code);
        }
    }
})();

This issue is caused by this line.

https://github.com/mizchi/uniroll/blob/d17c73bfc4a49677df21ca3c7d1768e356652f6b/packages/babel-plugin-transform-import-to-skypack-cdn/src/index.ts#L42 https://github.com/mizchi/uniroll/blob/d17c73bfc4a49677df21ca3c7d1768e356652f6b/packages/babel-plugin-transform-import-to-skypack-cdn/src/index.ts#L62

The scoped module includes / and the libraryName is wrong on the scoped module.

mizchi commented 3 years ago

I removed this plugin. Now it works on rollup-plugin-http-resolve.