Skip to content

Commit

Permalink
fix: support for yarn3
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian authored Sep 11, 2023
1 parent 7ba2e00 commit 6ab2458
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 58 deletions.
41 changes: 0 additions & 41 deletions scripts/generate-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,44 +77,3 @@ if (await fs.pathExists('HELP.md')) {
if (await fs.pathExists('images')) await fs.move('images', path.join(manifestDir, 'images'))
if (await fs.pathExists('documentation')) await fs.move('documentation', path.join(manifestDir, 'documentation'))
}

// for (const folder of dirs) {
// if (folder.match(/companion-module-/) && !ignoreNames.includes(folder)) {
// const moduleDir = path.join(outerDir, folder)
// const moduleNewDir = path.join(outerManifest, folder)
// const manifestDir = path.join(moduleNewDir, 'companion')

//
// await fs.mkdirp(manifestDir)
// await fs.writeFile(path.join(manifestDir, 'manifest.json'), JSON.stringify(manifest, undefined, '\t'))

// if (await fs.pathExists(( 'HELP.md'))) {
// await fs.copy(( 'HELP.md'), path.join(manifestDir, 'HELP.md'))

// // guess at what images might be needed by the help
// if (await fs.pathExists(( 'images')))
// await fs.copy(( 'images'), path.join(manifestDir, 'images'))
// if (await fs.pathExists(( 'documentation')))
// await fs.copy(( 'documentation'), path.join(manifestDir, 'documentation'))
// }

// await fs.writeFile(
// path.join(outerEntrypoints, `${pkgJson.name}.cjs`),
// `
// global.modulePkg = require('companion-module-${pkgJson.name}/package.json')
// global.moduleFactory = require('companion-module-${pkgJson.name}')
// global.moduleName = "${pkgJson.name}"
// import('../../dist/index.js')
// `
// )
// }
// }

// console.log('Bundling code. This will take a couple of minutes')
// await $`yarn webpack`

// // trick node into treating them all as cjs
// await fs.writeFile(`manifests/package.json`, '')

// // const useDir = await fs.pathExists('./module/legacy')
// // const baseDir = useDir ? './module/legacy' : './node_modules/companion-wrapped-module'
36 changes: 19 additions & 17 deletions webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
const path = require('path')

const frameworkDir = path.relative(process.cwd(), path.resolve('@companion-module/base'))
const pkgJson = require(path.join(process.cwd(), 'package.json'))
module.exports = async (env) => {
if (!env.ROOT) throw new Error(`Missing ROOT`)

if (!pkgJson.main) throw new Error(`Missing main in package.json`)
const frameworkDir = path.relative(env.ROOT, path.resolve('@companion-module/base'))
const pkgJson = require(path.join(env.ROOT, 'package.json'))

let webpackExt = {}
try {
webpackExt = require(path.join(process.cwd(), 'build-config.cjs'))
if (!pkgJson.main) throw new Error(`Missing main in package.json`)

console.log('Found additional webpack configuration')
} catch (e) {
// Ignore
}
let webpackExt = {}
try {
webpackExt = require(path.join(env.ROOT, 'build-config.cjs'))

let externalsExt = []
if (Array.isArray(webpackExt.externals)) externalsExt = webpackExt.externals
else if (webpackExt.externals) externalsExt = [webpackExt.externals]
console.log('Found additional webpack configuration')
} catch (e) {
// Ignore
}

let externalsExt = []
if (Array.isArray(webpackExt.externals)) externalsExt = webpackExt.externals
else if (webpackExt.externals) externalsExt = [webpackExt.externals]

module.exports = async (env) => {
return {
entry: {
main: './' + pkgJson.main, // path.join(frameworkDir, 'dist/entrypoint.js'),
Expand All @@ -28,9 +30,9 @@ module.exports = async (env) => {
mode: env.dev ? 'development' : 'production',
// devtool: env.dev ? undefined : 'source-map', // TODO - this would be nice, but I think the files have to be uploaded directly to sentry which is problematic...
output: {
path: path.resolve(process.cwd(), 'pkg'),
path: path.resolve(env.ROOT, 'pkg'),
},
context: path.resolve(process.cwd(), '.'),
context: path.resolve(env.ROOT, '.'),
target: 'node',
externals: [
// Allow for custom externals
Expand All @@ -39,7 +41,7 @@ module.exports = async (env) => {
experiments: {
topLevelAwait: true,
},
optimization: {
optimization: {
minimize: !webpackExt.disableMinifier,
},
module: {
Expand Down

0 comments on commit 6ab2458

Please sign in to comment.