rollup-plugin-typescript2
rollup-plugin-typescript2 copied to clipboard
test: dogfood rpt2 as `configPlugin` w/ `rollup.config.ts`
Summary
Dogfood rpt2 more by using it as a configPlugin on our own internal rollup.config.ts
Details
Motivation
-
use rpt2 as a
configPluginwithin 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-selfscript 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
- create a helper
TS Fixes
-
replace the unmaintained
rollup-plugin-rew/@rollup/plugin-replacerollup-plugin-rehasn'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
resolveplugin as it didn't type-check/had outdated usage
ESM Fixes
-
need to use
createRequirein ESM mode- deps: bump
@types/nodeto support the types for that as well - this is a BREAKING CHANGE as it requires Node 12+
- deps: bump
-
fix
fs-extraerror due to it being CJS -
require("package.json")->import- and add
resolveJsonModuletoconfigPlugintsconfigOverrideto handle this- only used by the
configPlugin, not everything else, so not added totsconfig.json
- only used by the
- and add
-
output as
build-self/index.mjsinstead ofbuild-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
- so that types work out of the box -- due to
Misc
#456 was split out of this as it took me quite a while to get builds to pass
As this is a breaking change due to use of createRequire, should probably go out in the same release as #458
Tests are failing due to use of createRequire... this might require bumping ts-jest 😕
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)
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