Skip to content

Commit

Permalink
Revert esm support for devextreme-react (#25581)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodDayForSurf authored Sep 13, 2023
1 parent 7c461ff commit 2d36f8c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 120 deletions.
113 changes: 4 additions & 109 deletions packages/devextreme-react/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 @@ -16,9 +15,6 @@ 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 @@ -69,59 +65,15 @@ gulp.task(NPM_README, gulp.series(
() => gulp.src(config.npm.readme).pipe(gulp.dest(config.npm.dist))
));

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.task(NPM_BUILD, gulp.series(
NPM_CLEAN,
gulp.parallel(NPM_LICENSE, NPM_PACKAGE, NPM_README),
() => gulp.src([
config.src,
`!${config.testSrc}`
])
.pipe(ts('tsconfig.json'))
.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
)
.pipe(gulp.dest(config.npm.dist))
));

gulp.task(NPM_BUILD_WITH_HEADERS, gulp.series(
Expand Down Expand Up @@ -159,62 +111,5 @@ 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);
})
} 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: 2 additions & 3 deletions packages/devextreme-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"type": "git",
"url": "https://github.com/DevExpress/devextreme-react.git"
},
"main": "./cjs/index.js",
"module": "./esm/index.js",
"types": "./cjs/index.d.ts",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"clean": "gulp clean",
"regenerate": "npm run clean && gulp generate",
Expand Down
8 changes: 0 additions & 8 deletions packages/devextreme-react/tsconfig.esm.json

This file was deleted.

0 comments on commit 2d36f8c

Please sign in to comment.