Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): Add custom rollup config for core #9297

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions app/scripts/modules/core/rollup.config.js
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,
vigneshm marked this conversation as resolved.
Show resolved Hide resolved
'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' }],
}),
vigneshm marked this conversation as resolved.
Show resolved Hide resolved
fixTSPathRewrite(),
],
external: externalConfigurer(externals),
};