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

Add ESM builds to devextreme-react #25483

Merged
merged 25 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e9752c2
restore component inline styles after unmounting if React.strictMode …
GoodDayForSurf Aug 21, 2023
0c347a1
lint fixes
GoodDayForSurf Aug 22, 2023
8946cb9
Merge branch '23_2' of https://github.com/GoodDayForSurf/DevExtreme i…
GoodDayForSurf Aug 22, 2023
b87858f
fix error
GoodDayForSurf Aug 22, 2023
2c34349
fix test
GoodDayForSurf Aug 22, 2023
11fbf5b
Merge branch '23_2' of https://github.com/GoodDayForSurf/DevExtreme i…
GoodDayForSurf Aug 23, 2023
8e8d293
Merge branch '23_2' of https://github.com/GoodDayForSurf/DevExtreme i…
GoodDayForSurf Aug 29, 2023
5fb44ce
add ESM building to package
GoodDayForSurf Aug 30, 2023
1cefebb
add ESM building to package
GoodDayForSurf Aug 30, 2023
950b62e
add ESM building to package
GoodDayForSurf Aug 30, 2023
7b9fa2d
add ESM building to package
GoodDayForSurf Sep 4, 2023
dc560ec
Fix "Invalid value used as weak map key" error (T1186521)
GoodDayForSurf Sep 4, 2023
33f2e82
Fix "Invalid value used as weak map key" error (T1186521)
GoodDayForSurf Sep 4, 2023
80fe3f5
Fix "Invalid value used as weak map key" error (T1186521)
GoodDayForSurf Sep 5, 2023
99b782d
Fix "Invalid value used as weak map key" error (T1186521)
GoodDayForSurf Sep 5, 2023
f508323
Fix "Invalid value used as weak map key" error (T1186521)
GoodDayForSurf Sep 5, 2023
d5246e0
Fix "Invalid value used as weak map key" error (T1186521)
GoodDayForSurf Sep 5, 2023
0af426f
Fix "Invalid value used as weak map key" error (T1186521)
GoodDayForSurf Sep 5, 2023
94b7bee
Fix "Invalid value used as weak map key" error (T1186521)
GoodDayForSurf Sep 5, 2023
3ac6722
Merge branch '23_2' of https://github.com/GoodDayForSurf/DevExtreme i…
GoodDayForSurf Sep 6, 2023
adf2115
add ESM building to package
GoodDayForSurf Sep 6, 2023
8f63004
Merge branch '23_2' of https://github.com/GoodDayForSurf/DevExtreme i…
GoodDayForSurf Sep 7, 2023
c12ce61
add ESM building to devextreme-react package
GoodDayForSurf Sep 7, 2023
c3c3d8b
add ESM building to devextreme-react package
GoodDayForSurf Sep 7, 2023
4af729c
add ESM building to devextreme-react package
GoodDayForSurf Sep 7, 2023
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
113 changes: 109 additions & 4 deletions packages/devextreme-react/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const shell = require('gulp-shell');
const header = require('gulp-header');
const ts = require('gulp-typescript');
const config = require('./build.config');
const path = require('path');

const GENERATE = 'generate';
const CLEAN = 'clean';
Expand All @@ -15,6 +16,9 @@ const NPM_LICENSE = 'npm.license';
const NPM_BUILD_WITH_HEADERS = 'npm.license-headers';
const NPM_README = 'npm.readme';
const NPM_BUILD = 'npm.build';
const NPM_BUILD_ESM = 'npm.build-esm';
const NPM_BUILD_CJS = 'npm.build-cjs';
const NPM_PREPARE_MODULES = 'npm.prepare-modules';
const NPM_PACK = 'npm.pack';

gulp.task(CLEAN, (c) =>
Expand Down Expand Up @@ -65,15 +69,59 @@ gulp.task(NPM_README, gulp.series(
() => gulp.src(config.npm.readme).pipe(gulp.dest(config.npm.dist))
));

gulp.task(NPM_BUILD, gulp.series(
NPM_CLEAN,
gulp.parallel(NPM_LICENSE, NPM_PACKAGE, NPM_README),
gulp.task(NPM_BUILD_ESM, gulp.series(
() => gulp.src([
config.src,
`!${config.testSrc}`
])
.pipe(ts('tsconfig.esm.json'))
.pipe(gulp.dest(config.npm.dist + '/esm'))
));

gulp.task(NPM_BUILD_CJS, gulp.series(
() => gulp.src([
config.src,
`!${config.testSrc}`
])
.pipe(ts('tsconfig.json'))
.pipe(gulp.dest(config.npm.dist))
.pipe(gulp.dest(config.npm.dist + '/cjs'))
));

gulp.task(NPM_PREPARE_MODULES, (done) => {
const packParamsForFolders = [
['common'],
['core', ['template']],
['common/data']
];
const modulesImportsFromIndex = fs.readFileSync(config.npm.dist + 'esm/index.js', 'utf8');
const modulesPaths = modulesImportsFromIndex.matchAll(/from "\.\/([^;]+)";/g);
const packParamsForModules = [...modulesPaths].map(
([, modulePath]) => {
const [,, moduleFilePath, moduleFileName] = modulePath.match(/((.*)\/)?([^/]+$)/);

return ['', [moduleFileName], moduleFilePath];
}
);

[
...packParamsForFolders,
...packParamsForModules,
].forEach(
([folder, moduleFileNames, moduleFilePath]) => makeModule(folder, moduleFileNames, moduleFilePath)
)

done();
});

gulp.task(NPM_BUILD, gulp.series(
NPM_CLEAN,
gulp.parallel(
NPM_LICENSE,
NPM_PACKAGE,
NPM_README,
NPM_BUILD_ESM,
NPM_BUILD_CJS
)
));

gulp.task(NPM_BUILD_WITH_HEADERS, gulp.series(
Expand Down Expand Up @@ -111,5 +159,62 @@ gulp.task(NPM_BUILD_WITH_HEADERS, gulp.series(

gulp.task(NPM_PACK, gulp.series(
NPM_BUILD_WITH_HEADERS,
NPM_PREPARE_MODULES,
shell.task(['npm pack'], {cwd: config.npm.dist})
));

function makeModule(folder, moduleFileNames, moduleFilePath) {
const distFolder = path.join(__dirname, config.npm.dist);
const distModuleFolder = path.join(distFolder, folder);
const distEsmFolder = path.join(distFolder, 'esm', folder);
const moduleNames = moduleFileNames || findJsModuleFileNamesInFolder(distEsmFolder);

try {
if (!fs.existsSync(distModuleFolder)) {
fs.mkdirSync(distModuleFolder);
}

if (folder && fs.existsSync(path.join(distEsmFolder, 'index.js'))) {
generatePackageJsonFile(folder);
}

moduleNames.forEach((moduleFileName) => {
fs.mkdirSync(path.join(distModuleFolder, moduleFileName));

generatePackageJsonFile(folder, moduleFileName, moduleFilePath);
})
GoodDayForSurf marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
error.message = `Exception while makeModule(${folder}).\n ${error.message}`;
throw(error);
}
}

function generatePackageJsonFile(folder, moduleFileName, filePath = folder) {
const moduleName = moduleFileName || '';
const absoluteModulePath = path.join(__dirname, config.npm.dist, folder, moduleName);
const moduleFilePath = (filePath ? filePath + '/' : '') + (moduleName || 'index');
const relativePath = path.relative(
absoluteModulePath,
path.join(__dirname, config.npm.dist, 'esm', moduleFilePath + '.js')
);

const relativeBase = '../'.repeat(relativePath.split('..').length - 1);

fs.writeFileSync(path.join(absoluteModulePath , 'package.json'), JSON.stringify({
sideEffects: false,
main: `${relativeBase}cjs/${moduleFilePath}.js`,
module: `${relativeBase}esm/${moduleFilePath}.js`,
typings: `${relativeBase}cjs/${moduleFilePath}.d.ts`,
}, null, 2));
}

function findJsModuleFileNamesInFolder(dir) {
return fs.readdirSync(dir).filter((file) => {
const filePath = path.join(dir, file);

return !fs.statSync(filePath).isDirectory()
&& file.includes('.js')
&& !file.includes('index.js')
}
).map((filePath) => path.parse(filePath).name);
}
5 changes: 3 additions & 2 deletions packages/devextreme-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"type": "git",
"url": "https://github.com/DevExpress/devextreme-react.git"
},
"main": "index.js",
"types": "index.d.ts",
"main": "./cjs/index.js",
"module": "./esm/index.js",
"types": "./cjs/index.d.ts",
"scripts": {
"clean": "gulp clean",
"regenerate": "npm run clean && gulp generate",
Expand Down
8 changes: 8 additions & 0 deletions packages/devextreme-react/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
GoodDayForSurf marked this conversation as resolved.
Show resolved Hide resolved
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node",
"declaration": false,
},
}
Loading