Skip to content

Commit 000bf0a

Browse files
committed
fix: migrate build from rollup to vite
Signed-off-by: Denis Golovin <[email protected]>
1 parent 4b322d6 commit 000bf0a

File tree

5 files changed

+732
-566
lines changed

5 files changed

+732
-566
lines changed

.extfiles

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package.json
2+
LICENSE
3+
icon.png
4+
README.md
5+
dist/**
6+
!dist/yarn.lock

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"engines": {
1010
"podman-desktop": "^0.16.0"
1111
},
12-
"main": "./dist/extension.js",
12+
"main": "./dist/extension.cjs",
1313
"source": "./src/extension.ts",
1414
"contributes": {
1515
"configuration": {
@@ -58,8 +58,8 @@
5858
}
5959
},
6060
"scripts": {
61-
"build": "rollup --bundleConfigAsCjs --config rollup.config.js --compact --environment BUILD:production",
62-
"watch": "rollup --bundleConfigAsCjs --config rollup.config.js -w",
61+
"build": "vite build && node scripts/build.cjs",
62+
"watch": "vite build -w",
6363
"lint:check": "eslint . --ext js,ts",
6464
"lint:fix": "eslint . --fix --ext js,ts",
6565
"format:check": "prettier --check src/**",
@@ -69,28 +69,27 @@
6969
"desk:run": "ts-node-esm ./scripts/run.mts run",
7070
"test": "vitest run --coverage --passWithNoTests"
7171
},
72-
"dependencies": {},
72+
"dependencies": {
73+
"@podman-desktop/api": "next"
74+
},
7375
"devDependencies": {
7476
"@podman-desktop/api": "next",
75-
"@rollup/plugin-commonjs": "^24.0.1",
76-
"@rollup/plugin-json": "^6.0.0",
77-
"@rollup/plugin-node-resolve": "^15.0.1",
78-
"@rollup/plugin-typescript": "^11.0.0",
7977
"@types/node": "^18.14.6",
8078
"@typescript-eslint/eslint-plugin": "^5.55.0",
8179
"@typescript-eslint/parser": "^5.55.0",
8280
"@vitest/coverage-v8": "^1.6.0",
83-
"7zip-min": "^1.4.4",
81+
"byline": "^5.0.0",
8482
"compare-versions": "^6.0.0-rc.1",
83+
"copyfiles": "^2.4.1",
8584
"eslint": "^8.36.0",
8685
"got": "^12.5.3",
8786
"hasha": "^5.2.2",
8887
"mkdirp": "^2.1.3",
8988
"prettier": "^2.8.4",
90-
"rollup": "^3.18.0",
9189
"ts-node": "^10.9.1",
9290
"tslib": "^2.5.0",
9391
"typescript": "^4.9.5",
92+
"vite": "^5.2.12",
9493
"vitest": "^1.6.0",
9594
"which": "^3.0.0",
9695
"zip-local": "^0.3.5"

scripts/build.cjs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env node
2+
/**********************************************************************
3+
* Copyright (C) 2022 - 2024 Red Hat, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* SPDX-License-Identifier: Apache-2.0
18+
***********************************************************************/
19+
20+
const zipper = require('zip-local');
21+
const path = require('path');
22+
const packageJson = require('../package.json');
23+
const { mkdirp } = require('mkdirp');
24+
const fs = require('fs');
25+
const byline = require('byline');
26+
const cp = require('copyfiles');
27+
const cproc = require('node:child_process');
28+
29+
const destFile = path.resolve(__dirname, `../${packageJson.name}.cdix`);
30+
const builtinDirectory = path.resolve(__dirname, '../builtin');
31+
const zipDirectory = path.resolve(builtinDirectory, `${packageJson.name}.cdix`);
32+
const extFiles = path.resolve(__dirname, '../.extfiles');
33+
const fileStream = fs.createReadStream(extFiles, { encoding: 'utf8' });
34+
35+
const includedFiles = [];
36+
const excludedFiles = [];
37+
38+
// remove the .cdix file before zipping
39+
if (fs.existsSync(destFile)) {
40+
fs.rmSync(destFile);
41+
}
42+
// remove the builtin folder before zipping
43+
if (fs.existsSync(builtinDirectory)) {
44+
fs.rmSync(builtinDirectory, { recursive: true, force: true });
45+
}
46+
47+
// install external modules into dist folder
48+
cproc.exec('yarn add hasha@^5.2.2 --cwd .', { cwd: './dist' }, (error, stdout, stderr) => {
49+
if (error) {
50+
console.log(stdout);
51+
console.log(stderr);
52+
throw error;
53+
}
54+
55+
byline(fileStream)
56+
.on('data', line => {
57+
line.startsWith('!') ? excludedFiles.push(line.substring(1)) : includedFiles.push(line);
58+
})
59+
.on('error', () => {
60+
throw new Error('Error reading .extfiles');
61+
})
62+
.on('end', () => {
63+
includedFiles.push(zipDirectory); // add destination dir
64+
mkdirp.sync(zipDirectory);
65+
console.log(`Copying files to ${zipDirectory}`);
66+
cp(includedFiles, { exclude: excludedFiles }, error => {
67+
if (error) {
68+
throw new Error('Error copying files', error);
69+
}
70+
console.log(`Zipping files to ${destFile}`);
71+
zipper.sync.zip(zipDirectory).compress().save(destFile);
72+
});
73+
});
74+
});

vite.config.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**********************************************************************
2+
* Copyright (C) 2023 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
import { join } from 'path';
20+
import { builtinModules } from 'module';
21+
22+
const PACKAGE_ROOT = __dirname;
23+
24+
/**
25+
* @type {import('vite').UserConfig}
26+
* @see https://vitejs.dev/config/
27+
*/
28+
const config = {
29+
mode: process.env.MODE,
30+
root: PACKAGE_ROOT,
31+
envDir: process.cwd(),
32+
resolve: {
33+
alias: {
34+
'/@/': join(PACKAGE_ROOT, 'src') + '/',
35+
},
36+
},
37+
optimizeDeps: {},
38+
build: {
39+
sourcemap: 'inline',
40+
target: 'esnext',
41+
outDir: 'dist',
42+
assetsDir: '.',
43+
minify: process.env.MODE === 'production' ? 'esbuild' : false,
44+
lib: {
45+
entry: 'src/extension.ts',
46+
formats: ['cjs'],
47+
},
48+
rollupOptions: {
49+
external: [
50+
'@podman-desktop/api',
51+
'hasha',
52+
...builtinModules.flatMap(p => [p, `node:${p}`]),
53+
],
54+
output: {
55+
entryFileNames: '[name].cjs',
56+
intro: 'const window = {}',
57+
},
58+
},
59+
emptyOutDir: true,
60+
reportCompressedSize: false,
61+
},
62+
};
63+
64+
export default config;

0 commit comments

Comments
 (0)