Skip to content

Commit 9898b72

Browse files
authored
chore: update clear-package-dir to check files array (#26645)
1 parent 6eefdee commit 9898b72

File tree

11 files changed

+28
-52
lines changed

11 files changed

+28
-52
lines changed

packages/gatsby-cli/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
"typescript": "^3.9.5"
6262
},
6363
"files": [
64-
"lib",
65-
"scripts",
64+
"lib/",
65+
"scripts/",
6666
"cli.js"
6767
],
6868
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-cli#readme",

packages/gatsby-core-utils/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
"url": "https://github.com/gatsbyjs/gatsby/issues"
2727
},
2828
"files": [
29-
"dist/",
30-
"dist/index.d.ts"
29+
"dist/"
3130
],
3231
"dependencies": {
3332
"ci-info": "2.0.0",
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
/*.js
2-
/__tests__
1+
/dist

packages/gatsby-design-tokens/.npmignore

-34
This file was deleted.

packages/gatsby-design-tokens/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"directory": "packages/gatsby-design-tokens"
1515
},
1616
"files": [
17-
"dist/**/*"
17+
"dist/"
1818
],
1919
"scripts": {
2020
"build": "npm run build:tokens && npm run build:theme && npm run build:theme-gatsbyjs-org",
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/dist/*.js
1+
/dist
22
yarn.lock
33
.tmp

packages/gatsby-legacy-polyfills/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"core-js-compat": "^3.6.5"
2828
},
2929
"files": [
30-
"dist/**"
30+
"dist/"
3131
],
3232
"devDependencies": {
3333
"chokidar-cli": "^2.1.0",

packages/gatsby-page-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"cross-env": "^5.2.1"
3838
},
3939
"files": [
40-
"dist/*"
40+
"dist/"
4141
],
4242
"engines": {
4343
"node": ">=10.13.0"

packages/gatsby-telemetry/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"jest-junit": "^6.4.0"
3535
},
3636
"files": [
37-
"lib",
38-
"src"
37+
"lib/",
38+
"src/"
3939
],
4040
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-telemetry#readme",
4141
"keywords": [

packages/gatsby/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,17 @@
186186
"files": [
187187
"apis.json",
188188
"ipc.json",
189-
"cache-dir",
189+
"cache-dir/",
190190
"cli.js",
191-
"dist",
192-
"gatsby-admin-public",
191+
"dist/",
192+
"gatsby-admin-public/",
193193
"graphql.js",
194194
"index.d.ts",
195195
"scripts/postinstall.js",
196196
"utils.js",
197197
"internal.js",
198198
"internal.d.ts",
199-
"!cache-dir/__tests__/"
199+
"!**/__tests__/"
200200
],
201201
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby#readme",
202202
"keywords": [

scripts/clear-package-dir.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,20 @@ const getListOfFilesToClear = ({ location, name }) => {
8787
npmignore = npmignore.concat([`node_modules/**`])
8888
}
8989

90-
const result = glob.sync(`**/*`, {
91-
nodir: true,
90+
let globPattern = `**/*`
91+
// check files array in package.json and use it as glob pattern
92+
try {
93+
const pkg = require(`${location}/package.json`)
94+
if (pkg.files && pkg.files.length) {
95+
globPattern =
96+
pkg.files.length > 1 ? `{${pkg.files.join(`,`)}}` : pkg.files[0]
97+
}
98+
} catch {
99+
// do nothing
100+
}
101+
102+
let result = []
103+
result = glob.sync(globPattern, {
92104
ignore: npmignore,
93105
cwd: location,
94106
})

0 commit comments

Comments
 (0)