Skip to content

Commit

Permalink
fix: build all scripts cannot running
Browse files Browse the repository at this point in the history
  • Loading branch information
blackcater committed May 20, 2021
1 parent 2574e79 commit 37279d9
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ lib/
cjs/
esm/
docs/.docgen/

# typescript
*.tsbuildinfo
1 change: 1 addition & 0 deletions configuration/rollup/create-package-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default async function createPackageConfig(config: PkgConfigInput): Promi
name: packageJson.name,
dir: path.resolve(config.basePath, 'cjs'),
format: 'cjs',
exports: 'named',
preserveModules: true,
// preserveModulesRoot: path.resolve(config.basePath, 'src'),
sourcemap: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "eslint src --ext .ts,.tsx",
"build": "esno scripts/build",
"jest": "jest",
"clean": "rimraf src/*/{esm,cjs,lib,dist}",
"clean": "rimraf src/*/{esm,cjs,lib,dist} src/**/*.tsbuildinfo",
"storybook": "esno scripts/storybook-start",
"test": "npm run syncpack && npm run typecheck && npm run lint && npm run jest",
"docs": "npm run docs:docgen && npm run docs:sizes && cd docs && npm start",
Expand Down
2 changes: 1 addition & 1 deletion scripts/calculate-sizes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function truncateNumber(number: number) {
}

function getPackageSize(packageName: string) {
const libPath = path.join(REPO_ROOT, 'src', packageName, 'dist/index.js');
const libPath = path.join(REPO_ROOT, 'src', packageName, 'lib/index.umd.js');

if (!fs.existsSync(libPath)) {
return { size: 0, gzip: 0 };
Expand Down
22 changes: 3 additions & 19 deletions scripts/utils/generate-dts.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { spawn } from 'child_process';
import execa from 'execa';

export default async function generateDts(packagePath: string) {
return new Promise((resolve, reject) => {
const child = spawn('yarn', ['tsc', '--emitDeclarationOnly'], {
cwd: packagePath,
});

child.on('close', (code) => {
if (code !== 0) reject(code);
else resolve(code);
});

child.on('exit', (code) => {
if (code !== 0) reject(code);
else resolve(code);
});

child.on('error', (err) => {
reject(err);
});
await execa('yarn', ['tsc', '--build'], {
cwd: packagePath,
});
}
70 changes: 40 additions & 30 deletions scripts/utils/get-packages-build-order.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
/* eslint-disable no-param-reassign, no-restricted-syntax, no-continue, no-await-in-loop */
import { getPackagesList, Package } from './get-packages-list';

export async function getPackageBuildOrder(
packages: Package[],
pkg: Package,
order: Record<string, number> = {}
) {
const { name } = pkg.packageJson;

if (name in order) return;
if (pkg.packageJson.private) {
order[name] = -1;
return;
}

packages = packages || [];

const dependencies = Object.keys({
...pkg.packageJson.peerDependencies,
...pkg.packageJson.dependencies,
})
.filter((dependency) => dependency.includes('@mantine/'))
.map((dependency) => packages.find((pkgItem) => pkgItem.packageJson.name === dependency));

if (dependencies.length === 0) {
order[name] = 0;
return;
}

await Promise.all(
dependencies.map((dependency) => getPackageBuildOrder(packages, dependency, order))
);

order[name] =
1 + Math.max(...dependencies.map((dependency) => order[dependency.packageJson.name]));
}

export async function getPackagesBuildOrder(
packages?: Package[],
order: Record<string, number> = {}
) {
const data = packages || (await getPackagesList());

for (const item of data) {
const { name } = item.packageJson;

if (name in order) {
continue;
}

if (item.packageJson.private) {
order[name] = -1;
continue;
}

const dependencies = Object.keys({
...item.packageJson.dependencies,
...item.packageJson.peerDependencies,
})
.filter((dependency) => dependency.includes('@mantine/'))
.map((dependency) => data.find((dataItem) => dataItem.packageJson.name === dependency));

if (dependencies.length === 0) {
order[name] = 0;
continue;
}

await getPackagesBuildOrder(dependencies, order);
order[name] =
1 + Math.max(...dependencies.map((dependency) => order[dependency.packageJson.name]));
packages = packages || (await getPackagesList());

for (const pkg of packages) {
await getPackageBuildOrder(packages, pkg, order);
}

return Object.keys(order)
.filter((p) => order[p] !== -1)
.sort((a, b) => order[a] - order[b])
.map((p) => data.find((dataItem) => dataItem.packageJson.name === p));
.map((p) => packages.find((dataItem) => dataItem.packageJson.name === p));
}
4 changes: 3 additions & 1 deletion src/mantine-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
"declarationDir": "lib"
"declarationDir": "lib",
"composite": true
},
"references": [{ "path": "../mantine-theme" }, { "path": "../mantine-hooks" }]
}
1 change: 1 addition & 0 deletions src/mantine-dates/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
Expand Down
1 change: 1 addition & 0 deletions src/mantine-demos/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
Expand Down
1 change: 1 addition & 0 deletions src/mantine-hooks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
Expand Down
4 changes: 3 additions & 1 deletion src/mantine-notifications/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
"declarationDir": "lib"
}
},
"references": [{ "path": "../mantine-core" }, { "path": "../mantine-hooks" }]
}
4 changes: 3 additions & 1 deletion src/mantine-tag-picker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
"declarationDir": "lib"
}
},
"references": [{ "path": "../mantine-core" }, { "path": "../mantine-hooks" }]
}
1 change: 1 addition & 0 deletions src/mantine-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
Expand Down
1 change: 1 addition & 0 deletions src/mantine-theme/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
Expand Down
1 change: 1 addition & 0 deletions src/mantine-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.base.json",
"include": ["./src", "./types", "../../configuration/types"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"declarationMap": true,
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"exclude": ["node_modules", "lib", "esm", "cjs", "**/*.story.ts?", "**/*.test.ts?"],
"compilerOptions": {
"target": "ESNext",
"target": "ES2015",
"lib": ["DOM", "ESNext"],
"module": "ESNext",
"moduleResolution": "Node",
Expand All @@ -13,7 +13,7 @@
"allowJs": true,
"baseUrl": ".",
"paths": {
"@mantine/*": ["src/mantine-*/src"]
"@mantine/*": ["./src/mantine-*/src"]
}
}
}
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3244,8 +3244,8 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1, ajv-keywords@^3.5.2:

ajv@^6.1.0, ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.2, ajv@^6.12.3, ajv@^6.12.4, ajv@^6.12.5:
version "6.12.6"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4"
integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==
resolved "https://registry.nlark.com/ajv/download/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4"
integrity sha1-uvWmLoArB9l3A0WG+MO69a3ybfQ=
dependencies:
fast-deep-equal "^3.1.1"
fast-json-stable-stringify "^2.0.0"
Expand Down Expand Up @@ -3378,8 +3378,8 @@ arg@^4.1.0:

argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==
resolved "https://registry.nlark.com/argparse/download/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
integrity sha1-vNZ5HqWuCXJeF+WtmIE0zUCz2RE=
dependencies:
sprintf-js "~1.0.2"

Expand Down Expand Up @@ -4516,8 +4516,8 @@ commander@6.1.0:

commander@^2.18.0, commander@^2.19.0, commander@^2.20.0:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
resolved "https://registry.npm.taobao.org/commander/download/commander-2.20.3.tgz?cache=0&sync_timestamp=1616364348904&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcommander%2Fdownload%2Fcommander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha1-/UhehMA+tIgcIHIrpIA16FMa6zM=

commander@^4.0.0, commander@^4.1.1:
version "4.1.1"
Expand Down Expand Up @@ -8629,7 +8629,7 @@ lodash.flattendeep@^4.4.0:

lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
resolved "https://registry.nlark.com/lodash.isequal/download/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA=

lodash.merge@^4.6.2:
Expand All @@ -8649,8 +8649,8 @@ lodash.uniq@4.5.0:

lodash@4.x, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.7.0:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
resolved "https://registry.nlark.com/lodash/download/lodash-4.17.21.tgz?cache=0&sync_timestamp=1618847150612&other_urls=https%3A%2F%2Fregistry.nlark.com%2Flodash%2Fdownload%2Flodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha1-Z5WRxWTDv/quhFTPCz3zcMPWkRw=

loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1, loose-envify@^1.4.0:
version "1.4.0"
Expand Down Expand Up @@ -11171,8 +11171,8 @@ semver@7.3.4:

semver@7.x, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
resolved "https://registry.nlark.com/semver/download/semver-7.3.5.tgz?cache=0&sync_timestamp=1618846864940&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fsemver%2Fdownload%2Fsemver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha1-C2Ich5NI2JmOSw5L6Us/EuYBjvc=
dependencies:
lru-cache "^6.0.0"

Expand Down Expand Up @@ -11792,8 +11792,8 @@ strip-indent@^3.0.0:

strip-json-comments@^3.1.0, strip-json-comments@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==
resolved "https://registry.npm.taobao.org/strip-json-comments/download/strip-json-comments-3.1.1.tgz?cache=0&sync_timestamp=1594571796132&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fstrip-json-comments%2Fdownload%2Fstrip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
integrity sha1-MfEoGzgyYwQ0gxwxDAHMzajL4AY=

strip-outer@^1.0.0:
version "1.0.1"
Expand Down Expand Up @@ -12409,7 +12409,7 @@ typedarray@^0.0.6:

typescript@^4.2.4:
version "4.2.4"
resolved "https://registry.nlark.com/typescript/download/typescript-4.2.4.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.nlark.com%2Ftypescript%2Fdownload%2Ftypescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
resolved "https://registry.nlark.com/typescript/download/typescript-4.2.4.tgz#8610b59747de028fda898a8aef0e103f156d0961"
integrity sha1-hhC1l0feAo/aiYqK7w4QPxVtCWE=

unbox-primitive@^1.0.0:
Expand Down

0 comments on commit 37279d9

Please sign in to comment.