Skip to content

Commit 6ee196f

Browse files
committed
fix: update export package
1 parent 815602c commit 6ee196f

File tree

2 files changed

+77
-74
lines changed

2 files changed

+77
-74
lines changed

scripts/build.js

+47-49
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
const childProcess = require('child_process');
2-
const path = require('path');
3-
const { promisify } = require('util');
4-
const yargs = require('yargs');
1+
const childProcess = require("child_process");
2+
const path = require("path");
3+
const { promisify } = require("util");
4+
const yargs = require("yargs");
55

66
const exec = promisify(childProcess.exec);
77

8-
const validBundles = ['stable'];
8+
const validBundles = ["stable"];
99

1010
async function run(argv) {
1111
const { bundle, largeFiles, outDir: relativeOutDir, verbose } = argv;
1212

1313
if (validBundles.indexOf(bundle) === -1) {
1414
throw new TypeError(
1515
`Unrecognized bundle '${bundle}'. Did you mean one of "${validBundles.join(
16-
'", "'
17-
)}"?`
16+
"\", \"",
17+
)}"?`,
1818
);
1919
}
2020

2121
const env = {
22-
NODE_ENV: 'production',
22+
NODE_ENV: "production",
2323
BABEL_ENV: bundle,
2424
MUI_BUILD_VERBOSE: verbose,
2525
};
26-
const babelConfigPath = path.resolve(__dirname, '../babel-build.config.js');
27-
const srcDir = path.resolve('./src');
28-
const extensions = ['.js', '.ts', '.tsx'];
26+
const babelConfigPath = path.resolve(__dirname, "../babel-build.config.js");
27+
const srcDir = path.resolve("./src");
28+
const extensions = [".js", ".ts", ".tsx"];
2929
const ignore = [
30-
'**/*.test.js',
31-
'**/*.test.ts',
32-
'**/*.test.tsx',
33-
'**/*.spec.ts',
34-
'**/*.spec.tsx',
35-
'**/*.d.ts',
36-
'**/__stories__/*',
37-
'**/*.stories.ts',
38-
'**/*.stories.js',
39-
'**/*.stories.tsx',
40-
'**/*.stories.jsx',
30+
"**/*.test.js",
31+
"**/*.test.ts",
32+
"**/*.test.tsx",
33+
"**/*.spec.ts",
34+
"**/*.spec.tsx",
35+
"**/*.d.ts",
36+
"**/__stories__/*",
37+
"**/*.stories.ts",
38+
"**/*.stories.js",
39+
"**/*.stories.tsx",
40+
"**/*.stories.jsx",
4141
];
4242

4343
const outDir = path.resolve(
4444
relativeOutDir,
4545
{
46-
stable: './',
47-
}[bundle]
46+
stable: "./",
47+
}[bundle],
4848
);
4949

5050
const babelArgs = [
51-
'--config-file',
51+
"--config-file",
5252
babelConfigPath,
53-
'--extensions',
54-
`"${extensions.join(',')}"`,
53+
"--extensions",
54+
`"${extensions.join(",")}"`,
5555
srcDir,
56-
'--out-dir',
56+
"--out-dir",
5757
outDir,
58-
'--ignore',
58+
"--ignore",
5959
// Need to put these patterns in quotes otherwise they might be evaluated by the used terminal.
60-
`"${ignore.join('","')}"`,
60+
`"${ignore.join("\",\"")}"`,
6161
];
6262
if (largeFiles) {
63-
babelArgs.push('--compact false');
63+
babelArgs.push("--compact false");
6464
}
6565

66-
const command = ['npx babel', ...babelArgs].join(' ');
66+
const command = ["npx babel", ...babelArgs].join(" ");
6767

6868
if (verbose) {
6969
// eslint-disable-next-line no-console
@@ -85,23 +85,21 @@ async function run(argv) {
8585

8686
yargs
8787
.command({
88-
command: '$0 <bundle>',
89-
description: 'build package',
90-
builder: (command) => {
91-
return command
92-
.positional('bundle', {
93-
description: `Valid bundles: "${validBundles.join('" | "')}"`,
94-
type: 'string',
95-
})
96-
.option('largeFiles', {
97-
type: 'boolean',
98-
default: false,
99-
describe:
100-
'Set to `true` if you know you are transpiling large files.',
101-
})
102-
.option('out-dir', { default: './dist', type: 'string' })
103-
.option('verbose', { type: 'boolean' });
104-
},
88+
command: "$0 <bundle>",
89+
description: "build package",
90+
builder: (command) => command
91+
.positional("bundle", {
92+
description: `Valid bundles: "${validBundles.join("\" | \"")}"`,
93+
type: "string",
94+
})
95+
.option("largeFiles", {
96+
type: "boolean",
97+
default: false,
98+
describe:
99+
"Set to `true` if you know you are transpiling large files.",
100+
})
101+
.option("out-dir", { default: "./dist", type: "string" })
102+
.option("verbose", { type: "boolean" }),
105103
handler: run,
106104
})
107105
.help()

scripts/copy-files.js

+30-25
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1+
/* eslint-disable no-unused-vars */
12
/* eslint-disable no-console */
2-
const path = require('path');
3-
const fse = require('fs-extra');
4-
const glob = require('fast-glob');
3+
const path = require("path");
4+
const fse = require("fs-extra");
5+
const glob = require("fast-glob");
56

67
const packagePath = process.cwd();
7-
const buildPath = path.join(packagePath, './dist');
8-
const srcPath = path.join(packagePath, './src');
8+
const buildPath = path.join(packagePath, "./dist");
9+
const srcPath = path.join(packagePath, "./src");
910

1011
async function createModulePackages({ from, to }) {
1112
const directoryPackages = glob
12-
.sync('*/index.{js,ts,tsx}', { cwd: from })
13+
.sync("*/index.{js,ts,tsx}", { cwd: from })
1314
.map(path.dirname);
1415

1516
await Promise.all(
1617
directoryPackages.map(async (directoryPackage) => {
17-
const packageJsonPath = path.join(to, directoryPackage, 'package.json');
18+
const packageJsonPath = path.join(to, directoryPackage, "package.json");
1819

1920
const packageJson = {
2021
sideEffects: false,
21-
module: './index.js',
22-
main: './index.js',
23-
types: './index.d.ts',
22+
module: "./index.js",
23+
main: "./index.js",
24+
types: "./index.d.ts",
2425
};
2526

2627
const [typingsEntryExist, moduleEntryExists, mainEntryExists] = await Promise.all([
@@ -55,7 +56,7 @@ async function createModulePackages({ from, to }) {
5556
if (manifestErrorMessages.length > 0) {
5657
// TODO: AggregateError
5758
throw new Error(
58-
`${packageJsonPath}:\n${manifestErrorMessages.join('\n')}`,
59+
`${packageJsonPath}:\n${manifestErrorMessages.join("\n")}`,
5960
);
6061
}
6162

@@ -64,7 +65,7 @@ async function createModulePackages({ from, to }) {
6465
);
6566
}
6667

67-
const packageIncludes = ['expressionparser', '@babel/runtime', 'lodash.isequal'];
68+
const packageIncludes = ["expressionparser", "@babel/runtime", "lodash.isequal", "react-dnd", "react-dnd-html5-backend"];
6869

6970
async function includeFileInBuild(file) {
7071
const sourcePath = path.resolve(packagePath, file);
@@ -88,11 +89,15 @@ async function includeFileInBuild(file) {
8889

8990
async function createPackageFile() {
9091
const packageData = await fse.readFile(
91-
path.resolve(packagePath, './package.json'),
92-
'utf8',
92+
path.resolve(packagePath, "./package.json"),
93+
"utf8",
9394
);
9495
const {
95-
nyc, scripts, devDependencies, workspaces, ...packageDataOther
96+
nyc,
97+
scripts,
98+
devDependencies,
99+
workspaces,
100+
...packageDataOther
96101
} = JSON.parse(packageData);
97102

98103
const { dependencies } = packageDataOther;
@@ -105,30 +110,30 @@ async function createPackageFile() {
105110
private: false,
106111
...(packageDataOther.main
107112
? {
108-
main: './index.js',
109-
module: './index.js',
113+
main: "./index.js",
114+
module: "./index.js",
110115
}
111116
: {}),
112-
types: './index.d.ts',
117+
types: "./index.d.ts",
113118
};
114119

115120
delete newPackageData.files;
116121

117-
const targetPath = path.resolve(buildPath, './package.json');
122+
const targetPath = path.resolve(buildPath, "./package.json");
118123

119124
await fse.writeFile(
120125
targetPath,
121126
JSON.stringify(newPackageData, null, 2),
122-
'utf8',
127+
"utf8",
123128
);
124129
console.log(`Created package.json in ${targetPath}`);
125130

126131
return newPackageData;
127132
}
128133

129134
async function prepend(file, string) {
130-
const data = await fse.readFile(file, 'utf8');
131-
await fse.writeFile(file, string + data, 'utf8');
135+
const data = await fse.readFile(file, "utf8");
136+
await fse.writeFile(file, string + data, "utf8");
132137
}
133138

134139
async function addLicense(packageData) {
@@ -139,11 +144,11 @@ async function addLicense(packageData) {
139144
*/
140145
`;
141146
await Promise.all(
142-
['./index.js'].map(async (file) => {
147+
["./index.js"].map(async (file) => {
143148
try {
144149
await prepend(path.resolve(buildPath, file), license);
145150
} catch (err) {
146-
if (err.code === 'ENOENT') {
151+
if (err.code === "ENOENT") {
147152
console.log(`Skipped license for ${file}`);
148153
} else {
149154
throw err;
@@ -159,7 +164,7 @@ async function run() {
159164

160165
await Promise.all(
161166
[
162-
'./README.md',
167+
"./README.md",
163168
// './CHANGELOG.md',
164169
// './LICENSE',
165170
].map((file) => includeFileInBuild(file)),

0 commit comments

Comments
 (0)