-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): Add custom rollup config for core
The `core` package has some unique characteristics that need a custom rollup config file rather than using the generic one from `@spinnaker/scripts`. This includes - copying over typescript definition files - defining an alias mapping for `root` - a plugin to fix typescript's path auto-rewrites.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import alias from '@rollup/plugin-alias'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import copy from 'rollup-plugin-copy'; | ||
|
||
import baseRollupConfig from '@spinnaker/scripts/config/rollup.config.base.module'; | ||
import externalConfigurer from '@spinnaker/scripts/helpers/rollup-node-auto-external-configurer'; | ||
|
||
const packageJSON = JSON.parse(fs.readFileSync('./package.json', 'utf8')); | ||
const externals = { | ||
...packageJSON.dependencies, | ||
'root/version': true, | ||
}; | ||
|
||
// In index.ts, the triple slash reference to global namespace types get re-written to match the 'core' alias | ||
// This kludge re-re-writes them back to a relative path | ||
// Likely related to https://github.com/microsoft/TypeScript/issues/36763 | ||
const fixTSPathRewrite = () => { | ||
return { | ||
name: 'fixTSPathRewrite', | ||
writeBundle: () => { | ||
const dts = path.join(__dirname, 'dist', 'index.d.ts'); | ||
const fixed = fs | ||
.readFileSync(dts) | ||
.toString() | ||
.replace(/types="core\/types"/, 'types="./types"'); | ||
fs.writeFileSync(dts, fixed); | ||
}, | ||
}; | ||
}; | ||
|
||
export default { | ||
...baseRollupConfig, | ||
plugins: [ | ||
...baseRollupConfig.plugins, | ||
alias({ | ||
entries: [{ find: 'root', replacement: path.join(__dirname, '../../../../') }], | ||
}), | ||
// `core` has some custom type declarations for `promise` and `svg` that needs to be bundled together in the | ||
// distribution. These custom type declarations are not automatically copied over by typescript, so needs to be | ||
// explicitly copied here. | ||
copy({ | ||
targets: [{ src: 'src/types/**/*', dest: 'dist/types' }], | ||
}), | ||
fixTSPathRewrite(), | ||
], | ||
external: externalConfigurer(externals), | ||
}; |