FlandreDaisuki / rollup-plugin-userscript-metablock

Transform json file to userscript metablock and append on.
https://www.npmjs.com/package/rollup-plugin-userscript-metablock
MIT License
35 stars 7 forks source link

Update to modern infra #27

Closed FlandreDaisuki closed 5 months ago

FlandreDaisuki commented 5 months ago

test!: replace mocha with vitest build!: replace npm with pnpm build!: update deps

cvzi commented 5 months ago

Sorry to bother you about this, but what do I need to change to support these changes?

Previously I was doing

import metablock from "rollup-plugin-userscript-metablock";

but now I get SyntaxError: The requested module 'rollup-plugin-userscript-metablock' does not provide an export named 'default'

FlandreDaisuki commented 5 months ago

sorry for inconvenience, I'll investigate this problem asap.

FlandreDaisuki commented 5 months ago

@cvzi I found that the problem is node resolution in package.json. I've tried to fix it in v0.4.1 and tested in my use-cases.

cvzi commented 5 months ago

Yes it works, thank you for the quick response!

cvzi commented 5 months ago

It still doesn't work with require e.g. const metablock = require('rollup-plugin-userscript-metablock')

const metablock = require('rollup-plugin-userscript-metablock')
                  ^

Error [ERR_REQUIRE_ESM]: require() of ES Module \node_modules\rollup-plugin-userscript-metablock\dist\rollup-plugin-userscript-metablock.common.js from my.js not supported.
rollup-plugin-userscript-metablock.common.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename rollup-plugin-userscript-metablock.common.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in node_modules\rollup-plugin-userscript-metablock\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Object.<anonymous> (my.js:8:19) {
  code: 'ERR_REQUIRE_ESM'
}

I tried the suggestion in the error and manually renamed the file dist/rollup-plugin-userscript-metablock.common.js to dist/rollup-plugin-userscript-metablock.common.cjs and that solves it.

FlandreDaisuki commented 5 months ago

@cvzi Thanks so much for the report!! ❤️ I just update to v0.4.2 and update the examples to following 3 situations:

  1. examples/CJS: implicit type in package.json & use commonjs in rollup.config.js build with no special flag
  2. examples/Project: explicit type: "module" in package.json & use esmodule in rollup.config.js build with no special flag
  3. examples/Started: implicit type in package.json & use esmodule in rollup.config.js build with --bundleConfigAsCjs flag

I hope I can cover all possible situations.