-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate build from rollup to vite
Signed-off-by: Denis Golovin <[email protected]>
- Loading branch information
Showing
5 changed files
with
732 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package.json | ||
LICENSE | ||
icon.png | ||
README.md | ||
dist/** | ||
!dist/yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env node | ||
/********************************************************************** | ||
* Copyright (C) 2022 - 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
const zipper = require('zip-local'); | ||
const path = require('path'); | ||
const packageJson = require('../package.json'); | ||
const { mkdirp } = require('mkdirp'); | ||
const fs = require('fs'); | ||
const byline = require('byline'); | ||
const cp = require('copyfiles'); | ||
const cproc = require('node:child_process'); | ||
|
||
const destFile = path.resolve(__dirname, `../${packageJson.name}.cdix`); | ||
const builtinDirectory = path.resolve(__dirname, '../builtin'); | ||
const zipDirectory = path.resolve(builtinDirectory, `${packageJson.name}.cdix`); | ||
const extFiles = path.resolve(__dirname, '../.extfiles'); | ||
const fileStream = fs.createReadStream(extFiles, { encoding: 'utf8' }); | ||
|
||
const includedFiles = []; | ||
const excludedFiles = []; | ||
|
||
// remove the .cdix file before zipping | ||
if (fs.existsSync(destFile)) { | ||
fs.rmSync(destFile); | ||
} | ||
// remove the builtin folder before zipping | ||
if (fs.existsSync(builtinDirectory)) { | ||
fs.rmSync(builtinDirectory, { recursive: true, force: true }); | ||
} | ||
|
||
// install external modules into dist folder | ||
cproc.exec('yarn add hasha@^5.2.2 --cwd .', { cwd: './dist' }, (error, stdout, stderr) => { | ||
if (error) { | ||
console.log(stdout); | ||
console.log(stderr); | ||
throw error; | ||
} | ||
|
||
byline(fileStream) | ||
.on('data', line => { | ||
line.startsWith('!') ? excludedFiles.push(line.substring(1)) : includedFiles.push(line); | ||
}) | ||
.on('error', () => { | ||
throw new Error('Error reading .extfiles'); | ||
}) | ||
.on('end', () => { | ||
includedFiles.push(zipDirectory); // add destination dir | ||
mkdirp.sync(zipDirectory); | ||
console.log(`Copying files to ${zipDirectory}`); | ||
cp(includedFiles, { exclude: excludedFiles }, error => { | ||
if (error) { | ||
throw new Error('Error copying files', error); | ||
} | ||
console.log(`Zipping files to ${destFile}`); | ||
zipper.sync.zip(zipDirectory).compress().save(destFile); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2023 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import { join } from 'path'; | ||
import { builtinModules } from 'module'; | ||
|
||
const PACKAGE_ROOT = __dirname; | ||
|
||
/** | ||
* @type {import('vite').UserConfig} | ||
* @see https://vitejs.dev/config/ | ||
*/ | ||
const config = { | ||
mode: process.env.MODE, | ||
root: PACKAGE_ROOT, | ||
envDir: process.cwd(), | ||
resolve: { | ||
alias: { | ||
'/@/': join(PACKAGE_ROOT, 'src') + '/', | ||
}, | ||
}, | ||
optimizeDeps: {}, | ||
build: { | ||
sourcemap: 'inline', | ||
target: 'esnext', | ||
outDir: 'dist', | ||
assetsDir: '.', | ||
minify: process.env.MODE === 'production' ? 'esbuild' : false, | ||
lib: { | ||
entry: 'src/extension.ts', | ||
formats: ['cjs'], | ||
}, | ||
rollupOptions: { | ||
external: [ | ||
'@podman-desktop/api', | ||
'hasha', | ||
...builtinModules.flatMap(p => [p, `node:${p}`]), | ||
], | ||
output: { | ||
entryFileNames: '[name].cjs', | ||
intro: 'const window = {}', | ||
}, | ||
}, | ||
emptyOutDir: true, | ||
reportCompressedSize: false, | ||
}, | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.