rollup-plugin-typescript2 icon indicating copy to clipboard operation
rollup-plugin-typescript2 copied to clipboard

test: dogfood rpt2 as `configPlugin` w/ `rollup.config.ts`

Open agilgur5 opened this issue 2 years ago • 4 comments
trafficstars

Summary

Dogfood rpt2 more by using it as a configPlugin on our own internal rollup.config.ts

Details

Motivation

  • use rpt2 as a configPlugin within our own build process, as well as to build itself

    • doubly dogfood
  • we don't have any tests for configPlugins, and it's a Rollup CLI option, so this is one of the few ways to test it

    • create a helper _build-self script so we don't need to type/repeat as much (or have as much potential for mistakes)
    • this ensures we don't have regressions like #426

TS Fixes

  • replace the unmaintained rollup-plugin-re w/ @rollup/plugin-replace

    • rollup-plugin-re hasn't had a commit in ~5 years and doesn't have typings (natively or in DT)
    • also import the plugins in the same order that they're used
  • fix the usage of the resolve plugin as it didn't type-check/had outdated usage

ESM Fixes

  • need to use createRequire in ESM mode

    • deps: bump @types/node to support the types for that as well
    • this is a BREAKING CHANGE as it requires Node 12+
  • fix fs-extra error due to it being CJS

  • require("package.json") -> import

    • and add resolveJsonModule to configPlugin tsconfigOverride to handle this
      • only used by the configPlugin, not everything else, so not added to tsconfig.json
  • output as build-self/index.mjs instead of build-self/dist/rollup-plugin-typescript2.es.js

    • so that types work out of the box -- due to index.d.ts
    • and so that Rollup correctly loads it as ESM and not CJS

Misc

#456 was split out of this as it took me quite a while to get builds to pass

agilgur5 avatar Jul 18 '23 22:07 agilgur5

As this is a breaking change due to use of createRequire, should probably go out in the same release as #458

agilgur5 avatar Jul 18 '23 22:07 agilgur5

Tests are failing due to use of createRequire... this might require bumping ts-jest 😕

agilgur5 avatar Jul 18 '23 22:07 agilgur5

I'm also getting an error on Windows trying one of the build_self scripts, a rollup issue?

> rollup -c rollup.config.self.ts --configPlugin ./build-self/index.mjs="{ tsconfigOverride: { compilerOptions: { resolveJsonModule: true } } }"

[!] Error: Cannot load plugin "C:\sandbox\other\rpt2\rollup-plugin-typescript2\build-self\index.mjs": Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'.
Error: Cannot load plugin "C:\sandbox\other\rpt2\rollup-plugin-typescript2\build-self\index.mjs": Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'.
    at loadAndRegisterPlugin (C:\sandbox\other\rpt2\rollup-plugin-typescript2\node_modules\rollup\dist\shared\loadConfigFile.js:508:23)
    at addPluginsFromCommandOption (C:\sandbox\other\rpt2\rollup-plugin-typescript2\node_modules\rollup\dist\shared\loadConfigFile.js:458:17)
    at getDefaultFromTranspiledConfigFile (C:\sandbox\other\rpt2\rollup-plugin-typescript2\node_modules\rollup\dist\shared\loadConfigFile.js:583:5)
    at loadConfigFile (C:\sandbox\other\rpt2\rollup-plugin-typescript2\node_modules\rollup\dist\shared\loadConfigFile.js:565:11)
    at Object.loadAndParseConfigFile (C:\sandbox\other\rpt2\rollup-plugin-typescript2\node_modules\rollup\dist\shared\loadConfigFile.js:545:21)
    at getConfigs (C:\sandbox\other\rpt2\rollup-plugin-typescript2\node_modules\rollup\dist\bin\rollup:1691:39)
    at runRollup (C:\sandbox\other\rpt2\rollup-plugin-typescript2\node_modules\rollup\dist\bin\rollup:1665:43)

ezolenko avatar Jul 30 '23 05:07 ezolenko

Dang thought we were past all Windows pathing issues 😅

Looks like something is expanding/converting the path in a way Rollup doesn't like ./build-self/index.mjs -> C:\sandbox\other\rpt2\rollup-plugin-typescript2\build-self\index.mjs. I'm not sure if Rollup is doing that expansion or something else (NPM as it's a script?), but I would think Rollup should know how to interpret that correctly 🤔 The error message makes it sound like potentially an ESM spec issue. So if Rollup is the one expanding it, it's expanding incorrectly for ESM. If it's NPM or something else expanding, that's a bit more of a head-scratcher

agilgur5 avatar Jul 30 '23 17:07 agilgur5