Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 3d61838

Browse files
태재영Matt Goo
태재영
authored and
Matt Goo
committed
fix(infrastructure): types generated directory problem (#952)
1 parent bdb3f43 commit 3d61838

File tree

7 files changed

+80
-35
lines changed

7 files changed

+80
-35
lines changed

packages/dialog/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Material Components React Dialog",
55
"license": "MIT",
66
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
78
"keywords": [
89
"mdc web react",
910
"material components react",

scripts/directory-reader.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ const {basename, join, resolve} = require('path');
33

44
const denyList = ['images'];
55

6-
const isDirectory = source => lstatSync(source).isDirectory();
7-
const getDirectories = source =>
8-
readdirSync(source).map(name => join(source, name)).filter(isDirectory);
6+
const isDirectory = (source) => lstatSync(source).isDirectory();
7+
const getDirectories = (source) =>
8+
readdirSync(source)
9+
.map((name) => join(source, name))
10+
.filter(isDirectory);
911

1012
function readScreenshotDirectory(
1113
components = [],
@@ -20,9 +22,15 @@ function readScreenshotDirectory(
2022
// recursively get sub directories
2123
const subDirectories = getDirectories(resolve(path, packageName));
2224
if (subDirectories.length > 0) {
23-
readScreenshotDirectory(components, resolve(path, packageName), packageName);
25+
readScreenshotDirectory(
26+
components,
27+
resolve(path, packageName),
28+
packageName
29+
);
2430
}
25-
components.push(`${parentDirectory ? parentDirectory + '/' : ''}${packageName}`);
31+
components.push(
32+
`${parentDirectory ? parentDirectory + '/' : ''}${packageName}`
33+
);
2634
});
2735

2836
return components;

scripts/package-json-reader.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const fs = require('fs');
22
const {resolve, join} = require('path');
3-
const packageJson = JSON.parse(fs.readFileSync(resolve(__dirname, '../package.json'), 'utf8'));
4-
3+
const packageJson = JSON.parse(
4+
fs.readFileSync(resolve(__dirname, '../package.json'), 'utf8')
5+
);
56

67
const readMaterialPackages = () => {
78
const dependencies = [
@@ -17,5 +18,4 @@ const readMaterialPackages = () => {
1718
return dependencies;
1819
};
1920

20-
2121
module.exports = {readMaterialPackages};

scripts/package-name-converter.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const {basename} = require('path');
22

3-
const dashedToCamel = (name) => name.replace(/-(\w)/g, (_, v) => v.toUpperCase());
3+
const dashedToCamel = (name) =>
4+
name.replace(/-(\w)/g, (_, v) => v.toUpperCase());
45

56
convertToImportMDCWebPaths = (packageNames) => {
67
return packageNames.map((packageName) => {
@@ -9,6 +10,6 @@ convertToImportMDCWebPaths = (packageNames) => {
910
// https://github.com/material-components/material-components-web/pull/3245
1011
return `@material/${name}/dist/mdc.${dashedToCamel(name)}`;
1112
});
12-
}
13+
};
1314

1415
module.exports = {convertToImportMDCWebPaths};

scripts/release/cp-pkgs.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@ const {sync: globSync} = require('glob');
3232

3333
const PKG_RE = /^(([a-z]*\-?)*)/;
3434

35-
const isValidCwd = (
35+
const isValidCwd =
3636
path.basename(process.cwd()) === 'material-components-web-react' &&
3737
fs.existsSync('packages') &&
38-
fs.existsSync('build')
39-
);
38+
fs.existsSync('build');
4039

4140
if (!isValidCwd) {
4241
console.error(
4342
'Invalid CWD. Please ensure you are running this from the root of the repo, ' +
44-
'and that you have run `npm run build`'
43+
'and that you have run `npm run build`'
4544
);
4645
process.exit(0);
4746
}
@@ -54,7 +53,9 @@ function getAssetEntry(asset) {
5453
function cpAsset(asset) {
5554
const assetPkg = path.join('packages', getAssetEntry(asset));
5655
if (!fs.existsSync(assetPkg)) {
57-
Promise.reject(new Error(`Non-existent asset package path ${assetPkg} for ${asset}`));
56+
Promise.reject(
57+
new Error(`Non-existent asset package path ${assetPkg} for ${asset}`)
58+
);
5859
}
5960

6061
let basename = path.basename(asset);
@@ -71,16 +72,20 @@ function cpAsset(asset) {
7172
}
7273

7374
const destDir = path.join(assetPkg, 'dist', basename);
74-
return cpFile(asset, destDir)
75-
.then(() => console.log(`cp ${asset} -> ${destDir}`));
75+
return cpFile(asset, destDir).then(() =>
76+
console.log(`cp ${asset} -> ${destDir}`)
77+
);
7678
}
7779

7880
// this takes a file path to an index.d.ts file and adds an //@ts-ignore comment
7981
// above the MDC Web imports (any line that includes `/dist/`). We need to ignore
8082
// these lines since MDC Web does not have typing files
8183
// TODO: https://github.com/material-components/material-components-web-react/issues/574
8284
function addTsIgnore(filePath) {
83-
const data = fs.readFileSync(filePath).toString().split('\n');
85+
const data = fs
86+
.readFileSync(filePath)
87+
.toString()
88+
.split('\n');
8489
const lineNumber = data.findIndex((lineText) => lineText.includes('/dist/'));
8590
if (lineNumber <= -1) return;
8691

@@ -100,8 +105,9 @@ function cpTypes(typeAsset) {
100105
destDir.splice(2, 0, 'dist');
101106
destDir = `${destDir.join('/')}/${base}`;
102107
addTsIgnore(typeAsset);
103-
return cpFile(typeAsset, destDir)
104-
.then(() => console.log(`cp ${typeAsset} -> ${destDir}`));
108+
return cpFile(typeAsset, destDir).then(() =>
109+
console.log(`cp ${typeAsset} -> ${destDir}`)
110+
);
105111
}
106112

107113
async function copyPackages() {
@@ -117,4 +123,3 @@ async function copyPackages() {
117123
}
118124

119125
copyPackages();
120-

scripts/release/verify-pkg-main.js

+41-12
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,66 @@ const isValidCwd = fs.existsSync('packages');
3131
if (!isValidCwd) {
3232
console.error(
3333
'Invalid CWD. Please ensure you are running this from the root of the repo, and that you have run ' +
34-
'`npm run dist` and `node scripts/cp-pkgs.js`'
34+
'`npm run dist` and `node scripts/cp-pkgs.js`'
3535
);
3636
process.exit(1);
3737
}
3838

3939
let invalidMains = 0;
40+
let invalidTypes = 0;
4041
globSync('packages/*/package.json').forEach((jsonPath) => {
4142
const packageInfo = JSON.parse(fs.readFileSync(jsonPath));
42-
if (!packageInfo.main) {
43-
return;
44-
}
45-
46-
const mainPath = path.join(path.dirname(jsonPath), packageInfo.main);
4743
let isInvalid = false;
44+
let isTypesInvalid = false;
45+
46+
const mainPath = path.join(path.dirname(jsonPath), packageInfo.main || '');
4847
if (mainPath.indexOf('dist') < 0) {
4948
isInvalid = true;
50-
console.error(`${jsonPath} main property does not reference a file under dist`);
49+
console.error(
50+
`${jsonPath} main property does not reference a file under dist`
51+
);
5152
}
5253
if (!fs.existsSync(mainPath)) {
5354
isInvalid = true;
54-
console.error(`${jsonPath} main property points to nonexistent ${mainPath}`);
55+
console.error(
56+
`${jsonPath} main property points to nonexistent ${mainPath}`
57+
);
58+
}
59+
const typesPath = path.join(path.dirname(jsonPath), packageInfo.types || '');
60+
if (typesPath.indexOf('dist') < 0) {
61+
isTypesInvalid = true;
62+
console.error(
63+
`${jsonPath} types property does not reference a file under dist`
64+
);
65+
}
66+
if (!fs.existsSync(typesPath)) {
67+
isTypesInvalid = true;
68+
console.error(
69+
`${jsonPath} types property points to nonexistent ${typesPath}`
70+
);
5571
}
5672

5773
if (isInvalid) {
5874
// Multiple checks could have failed, but only increment the counter once for one package.
5975
invalidMains++;
6076
}
77+
if (isTypesInvalid) {
78+
invalidTypes++;
79+
}
6180
});
62-
63-
if (invalidMains > 0) {
64-
console.error(`${invalidMains} incorrect main property values found; please fix.`);
81+
if (invalidMains > 0 || invalidTypes > 0) {
82+
if (invalidMains > 0) {
83+
console.error(
84+
`${invalidMains} incorrect main property values found; please fix.`
85+
);
86+
}
87+
if (invalidTypes > 0) {
88+
console.error(
89+
`${invalidTypes} incorrect types property values found; please fix.`
90+
);
91+
}
6592
} else {
66-
console.log('Success: All packages with main properties reference valid files under dist!');
93+
console.log(
94+
'Success: All packages with main/types properties reference valid files under dist!'
95+
);
6796
}

tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"extends": "gts/tsconfig-google.json",
33
"compilerOptions": {
4-
"outDir": "./types/",
4+
"outDir": "./build",
5+
"declarationDir": "./build/types",
56
"sourceMap": true,
67
"module": "commonjs",
78
"lib": ["es2015", "es2017", "dom"],
89
"jsx": "react",
910
"target": "es5",
1011
"noUnusedLocals": true,
1112
"noUnusedParameters": true,
12-
"esModuleInterop": true,
13+
"esModuleInterop": true
1314
},
1415
"compileOnSave": true,
1516
"exclude": [

0 commit comments

Comments
 (0)