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(custom-element): new es build module #7031

Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ packages/*/build/
packages/*/examples/*/build/
packages/*/scss
es
es-custom
lib
dist
umd
Expand Down
2 changes: 2 additions & 0 deletions packages/ibm-products-web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"files": [
"custom-elements.json",
"es/**/*",
"es-custom/**/*",
"lib/**/*",
"scss/**/*"
],
Expand All @@ -24,6 +25,7 @@
},
"exports": {
"./es/*": "./es/*",
"./es-custom/*": "./es-custom/*",
"./lib/*": "./lib/*",
"./dist/*": "./dist/*",
"./scss/*": "./scss/*",
Expand Down
52 changes: 34 additions & 18 deletions packages/ibm-products-web-components/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import path from 'path';
import postcss from 'postcss';
import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
import fs from 'fs-extra';

import * as packageJson from '../package.json' assert { type: 'json' };

Expand Down Expand Up @@ -55,14 +56,8 @@ async function build() {
};

const formats = [
{
type: 'esm',
directory: 'es',
},
{
type: 'commonjs',
directory: 'lib',
},
{ type: 'esm', directory: 'es' },
{ type: 'commonjs', directory: 'lib' },
];

for (const format of formats) {
Expand Down Expand Up @@ -90,6 +85,8 @@ async function build() {
sourcemap: true,
});
}

await postBuild();
}

const banner = `/**
Expand Down Expand Up @@ -131,9 +128,7 @@ function getRollupConfig(input, rootDir, outDir, iconInput) {
mainFields: ['jsnext', 'module', 'main'],
extensions: ['.js', '.ts'],
}),
commonjs({
include: [/node_modules/],
}),
commonjs({ include: [/node_modules/] }),
litSCSS({
includePaths: [
path.resolve(__dirname, '../node_modules'),
Expand All @@ -147,13 +142,7 @@ function getRollupConfig(input, rootDir, outDir, iconInput) {
).css;
},
}),
typescript({
noEmitOnError: true,
compilerOptions: {
rootDir,
outDir,
},
}),
typescript({ noEmitOnError: true, compilerOptions: { rootDir, outDir } }),
],
};
}
Expand All @@ -162,3 +151,30 @@ build().catch((error) => {
console.log(error);
process.exit(1);
});

async function postBuild() {
const sourceDir = path.resolve(__dirname, '../es');

if (sourceDir) {
const targetDir = path.resolve(__dirname, '../es-custom');

// Copy `es` directory to `es-custom`
await fs.copy(sourceDir, targetDir);

// Find all files in the `es-custom` directory
const files = await globby([`${targetDir}/**/*`], { onlyFiles: true });

// Replace "cds" with "cds-custom" in all files
await Promise.all(
files.map(async (file) => {
let content = await fs.promises.readFile(file, 'utf8');
content = content.replace(/cds/g, 'cds-custom');
content = content.replace(
/import\s+['"]@carbon\/web-components\/es\/components\/(.*?)['"]/g,
"import '@carbon/web-components/es-custom/components/$1'"
);
await fs.promises.writeFile(file, content);
})
);
}
}
Loading