Skip to content

Commit 67db9b0

Browse files
authored
Merge pull request #249 from semantic-release/revert-247-fix/asset-publish
Revert "Fix/asset-publish"
2 parents af008dc + 6d59933 commit 67db9b0

File tree

5 files changed

+20
-75
lines changed

5 files changed

+20
-75
lines changed

lib/publish.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function publish(
2929
const zipResult = config.withAssets
3030
? await execa(
3131
zipCommand,
32-
['-qr', path.join(releaseDir, `assets.zip`), '.'],
32+
['-qjr', path.join(releaseDir, `assets.zip`), assetDir],
3333
{
3434
cwd: assetDir,
3535
timeout: 30 * 1000,

package-lock.json

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"devDependencies": {
4747
"@babel/core": "7.24.7",
4848
"@babel/preset-env": "7.24.7",
49-
"@types/adm-zip": "^0.5.5",
5049
"@types/fs-extra": "11.0.4",
5150
"@types/jest": "29.5.12",
5251
"@types/node": "20.14.7",
@@ -55,7 +54,6 @@
5554
"@types/sinon": "17.0.3",
5655
"@typescript-eslint/eslint-plugin": "6.21.0",
5756
"@typescript-eslint/parser": "6.21.0",
58-
"adm-zip": "^0.5.16",
5957
"babel-jest": "29.7.0",
6058
"eslint": "8.56.0",
6159
"eslint-config-prettier": "9.1.0",

test/2-prepare-plugin.spec.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,17 @@ describe('Package preparation - default work directory', () => {
212212
contexts.prepareContext,
213213
);
214214

215-
const assets = new Set(
216-
fs.readdirSync(path.join(releasePath, 'assets'), {
217-
recursive: true,
218-
}) as string[],
219-
);
215+
const assets = fs.readdirSync(path.join(releasePath, 'assets'));
220216

221-
expect([...assets]).toHaveLength(6);
222-
expect(assets).toEqual(
223-
new Set([
217+
expect(assets).toHaveLength(5);
218+
expect(assets.sort()).toStrictEqual(
219+
[
224220
'blueprints',
225-
'blueprints/blueprint.json',
226221
'banner-low.jpg',
227222
'banner-high.jpg',
228223
'screenshot-1.jpg',
229224
'screenshot-2.jpg',
230-
]),
225+
].sort(),
231226
);
232227
});
233228
});

test/3-publish-plugin.spec.ts

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { replaceVersions } from '../lib/utils/replace-versions.js';
88
import { success } from '../lib/success.js';
99
import SemanticReleaseError from '@semantic-release/error';
1010
import { publish } from '../lib/publish.js';
11-
import AdmZip, { IZipEntry } from 'adm-zip';
1211

1312
const pluginConfig: PluginConfig = {
1413
type: 'plugin',
@@ -22,37 +21,12 @@ const pluginConfig: PluginConfig = {
2221
workDir: 'publish',
2322
};
2423

25-
let wDir: string;
24+
let releasePath: string;
2625
const env = process.env;
2726

28-
function readZip(dir: string, file: string, pfx: RegExp = /.^/): Set<string> {
29-
return new Set(
30-
new AdmZip(path.join(dir, file))
31-
.getEntries()
32-
.map(({ entryName }) => entryName.replace(pfx, '').replace(/\/$/, ''))
33-
.filter((e) => e !== '' && (pfx.source == '.^' || !e.match(/\//))),
34-
);
35-
}
36-
37-
function readDir(
38-
root: string,
39-
dir: string,
40-
recursive: boolean = false,
41-
): Set<string> {
42-
return new Set(
43-
fs.readdirSync(path.join(root, dir), {
44-
recursive,
45-
}) as string[],
46-
);
47-
}
48-
49-
function readFile(root: string, file: string): string {
50-
return fs.readFileSync(path.join(root, file), 'utf8');
51-
}
52-
5327
beforeAll(async () => {
54-
wDir = fs.mkdtempSync('/tmp/wp-release-');
55-
pluginConfig.releasePath = wDir;
28+
releasePath = fs.mkdtempSync('/tmp/wp-release-');
29+
pluginConfig.releasePath = releasePath;
5630
});
5731

5832
beforeEach(() => {
@@ -77,30 +51,28 @@ afterEach(async () => {
7751
});
7852

7953
afterAll(async () => {
80-
fs.removeSync(wDir);
54+
fs.removeSync(releasePath);
8155
});
8256

8357
describe('Publish step', () => {
84-
it('Should zip a complete plugin properly', async () => {
58+
it('Should package a complete plugin', async () => {
8559
await prepare(pluginConfig, contexts.publishContext);
8660
await publish(pluginConfig, contexts.publishContext);
8761

88-
expect(readFile(path.join(wDir, 'dist-test'), 'readme.txt')).toMatch(
89-
/^Stable tag: 1.0.0$/gm,
90-
);
91-
expect(readZip(wDir, 'package.zip', /^dist-test\//)).toEqual(
92-
readDir(wDir, 'dist-test'),
93-
);
94-
expect(readZip(wDir, 'assets.zip')).toEqual(readDir(wDir, 'assets', true));
95-
expect(readFile(wDir, 'VERSION')).toEqual('1.0.0');
62+
const distFolder = fs
63+
.readdirSync(path.join(releasePath, 'dist-test'))
64+
.join(' ');
9665

97-
// expect readZip(releasePath, 'assets.zip');
66+
expect(distFolder).not.toContain('node_modules');
67+
expect(distFolder).toContain('vendor');
68+
expect(distFolder).toContain('dist-test.php');
69+
expect(distFolder).toContain('test1.php');
9870
});
9971

10072
it('Should should remove folders on success', async () => {
10173
await success(pluginConfig, contexts.publishContext);
10274

103-
const files = fs.readdirSync(wDir).join(' ');
75+
const files = fs.readdirSync(releasePath).join(' ');
10476

10577
expect(files).toContain('package.zip');
10678
expect(files).toContain('assets.zip');
@@ -113,7 +85,7 @@ describe('Publish step', () => {
11385
try {
11486
await prepare(pluginConfig, contexts.publishContext);
11587

116-
await fs.remove(path.join(wDir, 'assets'));
88+
await fs.remove(path.join(releasePath, 'assets'));
11789
await publish(pluginConfig, contexts.publishContext);
11890
} catch (err) {
11991
expect((err as SemanticReleaseError).code).toMatch(/(ENOENT|EZIP)/);

0 commit comments

Comments
 (0)