Skip to content

Commit 63fb045

Browse files
authored
Merge pull request #241 from semantic-release/fix/globs
fix: Fixed nested globbing
2 parents 1f2e079 + 3e7ebf1 commit 63fb045

File tree

12 files changed

+127
-15
lines changed

12 files changed

+127
-15
lines changed

lib/utils/copy-assets.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export async function copyAssets(
1111
const basePath = path.resolve(path.join(workDir, '.wordpress-org', 'assets'));
1212

1313
const assets = await glob(
14-
['screenshot*', 'banner-*'].map((g) => `${g}.{jpg,png,gif,jpeg}`),
14+
[
15+
...['icon-*', 'screenshot*', 'banner-*'].map(
16+
(g) => `${g}.{jpg,png,gif,jpeg}`,
17+
),
18+
'blueprints/**.json',
19+
],
1520
{
1621
cwd: basePath,
1722
},

lib/utils/copy-files.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export function getInclude(workDir: string, files?: string[]): string[] {
2828
...new Set(getFileArray(workDir, '.distinclude') ?? files ?? []),
2929
];
3030

31-
return include.length !== 0 ? include : ['**/*'];
31+
return include.length > 0
32+
? include
33+
.filter((p) => p.includes('*') || fs.existsSync(path.join(workDir, p)))
34+
.map((p) => remapGlobs(workDir, p))
35+
: ['**'];
3236
}
3337

3438
/**
@@ -51,8 +55,7 @@ export function getIgnore(workDir: string, files?: string[]): string[] {
5155
.filter(
5256
(ignorePath) =>
5357
ignorePath.includes('*') ||
54-
(!ignorePath.includes('*') &&
55-
fs.existsSync(path.join(workDir, ignorePath))),
58+
fs.existsSync(path.join(workDir, ignorePath)),
5659
)
5760
.map((ignorePath) => remapGlobs(workDir, ignorePath));
5861
}
@@ -67,7 +70,8 @@ export async function copyFiles(
6770
const files = await glob(getInclude(workDir, config.include), {
6871
cwd: workDir,
6972
ignore: getIgnore(workDir, config.exclude),
70-
// maxDepth: 1,
73+
nodir: true,
74+
mark: true,
7175
});
7276

7377
await fs.mkdir(releasePath, { recursive: true });

test/0-corner-cases.spec.ts

+39-4
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,51 @@ describe('Corner cases affecting releases', () => {
8989
const ignore1 = DEFAULT_EXCLUDES;
9090
const include2 = getInclude(workDir, ['dist-test.php']);
9191
const ignore2 = getIgnore(workDir);
92-
const expected = ['dist-test.php', 'test1.php', 'vendor'].sort();
92+
const expected = [
93+
'dist-test.php',
94+
'test1.php',
95+
'vendor/composer.php',
96+
].sort();
9397

94-
expect(include1.sort()).toEqual(['dist-test.php', 'test1.php', 'vendor']);
98+
expect(include1.sort()).toEqual([
99+
'dist-test.php',
100+
'test1.php',
101+
'vendor/**',
102+
]);
95103
expect(
96104
(
97-
await glob(include1, { cwd: workDir, ignore: ignore1, maxDepth: 1 })
105+
await glob(include1, {
106+
cwd: workDir,
107+
ignore: ignore1,
108+
nodir: true,
109+
mark: true,
110+
})
98111
).sort(),
99112
).toEqual(expected);
100113
expect(
101-
(await glob(include2, { cwd: workDir, ignore: ignore2 })).sort(),
114+
(
115+
await glob(include2, {
116+
cwd: workDir,
117+
ignore: ignore2,
118+
nodir: true,
119+
mark: true,
120+
})
121+
).sort(),
102122
).toEqual(['dist-test.php']);
103123
});
124+
125+
it('Should glob properly with nesting', async () => {
126+
const workDir = path.resolve('./test/fixtures/nested-exclude');
127+
128+
expect(
129+
(
130+
await glob(getInclude(workDir), {
131+
cwd: workDir,
132+
ignore: getIgnore(workDir),
133+
nodir: true,
134+
mark: true,
135+
})
136+
).sort(),
137+
).toEqual(['assets/need-this.js', 'file.php']);
138+
});
104139
});

test/2-prepare-plugin.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ describe('Package preparation - default work directory', () => {
217217

218218
const assets = fs.readdirSync(path.join(releasePath, 'assets'));
219219

220-
expect(assets).toHaveLength(4);
220+
expect(assets).toHaveLength(5);
221221
expect(assets.sort()).toStrictEqual(
222222
[
223+
'blueprints',
223224
'banner-low.jpg',
224225
'banner-high.jpg',
225226
'screenshot-1.jpg',

test/2-prepare-theme.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ beforeEach(() => {
4141
afterEach(async () => {
4242
fs.rmSync('/tmp/workDir', { recursive: true, force: true });
4343
fs.rmSync('/tmp/wp-release', { recursive: true, force: true });
44+
fs.rmSync('./test/fixtures/complete-theme-copy', {
45+
recursive: true,
46+
force: true,
47+
});
4448
});
4549

4650
it('Should fail on a badly versioned theme', async () => {
@@ -131,9 +135,4 @@ it('Should fully prepare a theme for release', async () => {
131135
);
132136
expect(versions).toMatch(/1\.0\.0/);
133137
expect(versions).toMatch(/3\.2\.111/);
134-
135-
await fs.rm('./test/fixtures/complete-theme-copy', {
136-
recursive: true,
137-
force: true,
138-
});
139138
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"landingPage": "/wp-admin/index.php",
3+
"preferredVersions": {
4+
"php": "8.0",
5+
"wp": "6.4"
6+
},
7+
"phpExtensionBundles": ["kitchen-sink"],
8+
"steps": [
9+
{
10+
"step": "login",
11+
"username": "admin",
12+
"password": "password"
13+
},
14+
{
15+
"step": "setSiteOptions",
16+
"options": {
17+
"WPLANG": "sr_RS",
18+
"wcsrb_settings_general": "a:3:{s:22:\"enabled_customer_types\";s:4:\"both\";s:22:\"remove_unneeded_fields\";s:3:\"yes\";s:19:\"fix_currency_symbol\";s:3:\"yes\";}",
19+
"woocommerce_store_name": "Oblak Solutions DOO",
20+
"woocommerce_store_address": "Pozeska",
21+
"woocommerce_store_city": "Beograd",
22+
"woocommerce_store_postcode": "11000",
23+
"woocommerce_default_country": "RS:RS00",
24+
"woocommerce_store_bank_accounts": {
25+
"acct": ["160-428634-06"]
26+
},
27+
"woocommerce_currency": "RSD",
28+
"woocommerce_currency_pos": "right_space",
29+
"woocommerce_wcsrb_payment_slip_settings": {
30+
"enabled": "yes",
31+
"title": "Op\u0161ta uplatnica",
32+
"description": "Platite narud\u017ebinu op\u0161tom uplatnicom",
33+
"basic": "",
34+
"style": "modern",
35+
"bank_account": "160-428634-06",
36+
"payment_code": "auto",
37+
"payment_model": "mod97",
38+
"payment_reference": "%mod97%-%order_id%-%year%",
39+
"payment_purpose": "Pla\u0107anje narud\u017ebine",
40+
"qrcode": "",
41+
"qrcode_shown": "yes",
42+
"qrcode_color": "#000000",
43+
"qrcode_corner_color": "#0e77c0",
44+
"qrcode_image": "no",
45+
"advanced": "",
46+
"debug": "no"
47+
}
48+
}
49+
},
50+
{
51+
"step": "installPlugin",
52+
"pluginZipFile": {
53+
"resource": "wordpress.org/plugins",
54+
"slug": "woocommerce"
55+
},
56+
"options": {
57+
"activate": true
58+
}
59+
},
60+
{
61+
"step": "runPHP",
62+
"code": "<?php\ninclude 'wordpress/wp-load.php';\ndelete_transient('_wc_activation_redirect');"
63+
}
64+
]
65+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assets/src/**/*.*
2+
assets/ignore-this.js
3+
example.js

test/fixtures/nested-exclude/assets/ignore-this.js

Whitespace-only changes.

test/fixtures/nested-exclude/assets/need-this.js

Whitespace-only changes.

test/fixtures/nested-exclude/assets/src/file.css

Whitespace-only changes.

test/fixtures/nested-exclude/example.js

Whitespace-only changes.

test/fixtures/nested-exclude/file.php

Whitespace-only changes.

0 commit comments

Comments
 (0)