diff --git a/packages/dashmate/package.json b/packages/dashmate/package.json index e6a1f37e966..e1db9c29b54 100644 --- a/packages/dashmate/package.json +++ b/packages/dashmate/package.json @@ -125,7 +125,7 @@ "bin", "configs", "docker", - "src", + "dist", "templates", "docker-compose.*", "oclif.manifest.json", diff --git a/scripts/pack_dashmate.sh b/scripts/pack_dashmate.sh index b99693ed869..feb16ffda31 100755 --- a/scripts/pack_dashmate.sh +++ b/scripts/pack_dashmate.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -ex cmd_usage="Usage: pack_dashmate.sh COMMAND @@ -32,15 +32,28 @@ ROOT_PATH=$(dirname "$DIR_PATH") export NODE_ENV=production cd $ROOT_PATH/packages/dashmate || exit 1 + +# Build and copy artifacts to package +yarn build + +# Isolate dashmate package from workspace yarn pack --install-if-needed tar zxvf package.tgz -C . + cd $ROOT_PATH/packages/dashmate/package || exit 1 + +# Install dependencies cp $ROOT_PATH/yarn.lock ./yarn.lock mkdir .yarn echo "nodeLinker: pnpm" > .yarnrc.yml -# TODO: Remove bundled dependencies from package.json +# Remove already bundled dependencies +node "$DIR_PATH"/patch_dashmate_package_json.js yarn install --no-immutable + +# Create oclif manifest yarn oclif manifest + +# Pack dashmate into package yarn oclif pack $COMMAND $FLAGS cd .. || exit 1 rm package.tgz diff --git a/scripts/patch_dashmate_package_json.js b/scripts/patch_dashmate_package_json.js new file mode 100644 index 00000000000..22613a1f16b --- /dev/null +++ b/scripts/patch_dashmate_package_json.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const path = require('path'); + +// Step 1: Read the build.js file and extract the external array +const buildJsContent = fs.readFileSync(path.join(__dirname, '../packages/dashmate/scripts/build.js'), 'utf8'); +const externalMatch = buildJsContent.match(/external: \[([^\]]+)\]/); +if (!externalMatch) { + console.error('Could not find external array in build.js'); + process.exit(1); +} +const external = externalMatch[1].split(',').map(s => s.trim().replace(/['"]/g, '')); + +// Step 2: Read the package.json file and parse it into a JSON object +const packageJsonPath = path.join(__dirname, '../packages/dashmate/package/package.json'); +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); + +// Step 3: Iterate over the dependencies in the package.json object and remove any that are not in the external array +for (const dep in packageJson.dependencies) { + if (!external.includes(dep)) { + delete packageJson.dependencies[dep]; + } +} + +// Step 3: Iterate over the dependencies in the package.json object and remove any that are not in the external array +for (const dep in packageJson.devDependencies) { + if (dep !== 'oclif') { + delete packageJson.devDependencies[dep]; + } +} + +// Step 5: Write the modified package.json object back to the package.json file +fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));