Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,30 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Build distribution
- name: Build full distribution
run: npm run build

- name: Build simple distribution
run: SIMPLE_MODE=true BUILD_OUTPUT_DIR=dist-simple npm run build

- name: Extract version
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=${VERSION}" >> $GITHUB_OUTPUT

- name: Package distribution
- name: Package full distribution
run: npm run package

- name: Package simple distribution
run: BUILD_OUTPUT_DIR=dist-simple npm run package
Comment on lines +47 to +48
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Set SIMPLE_MODE=true during simple packaging, or the “simple” zip can contain default-mode output.

npm run package triggers a build again, so at Line 48 the rebuild runs without simple mode and can overwrite dist-simple with default-mode assets before zipping.

✅ Minimal fix
-      - name: Package simple distribution
-        run: BUILD_OUTPUT_DIR=dist-simple npm run package
+      - name: Package simple distribution
+        run: SIMPLE_MODE=true BUILD_OUTPUT_DIR=dist-simple npm run package
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Package simple distribution
run: BUILD_OUTPUT_DIR=dist-simple npm run package
- name: Package simple distribution
run: SIMPLE_MODE=true BUILD_OUTPUT_DIR=dist-simple npm run package
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/build-and-publish.yml around lines 47 - 48, The "Package
simple distribution" step re-runs the build without simple mode and can
overwrite dist-simple; set SIMPLE_MODE=true when invoking the package/build step
so the rebuild produces simple-mode assets (e.g. run the package step with
SIMPLE_MODE=true and BUILD_OUTPUT_DIR=dist-simple) to ensure the zip contains
simple-mode output and not default-mode files.


- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist-${{ steps.version.outputs.version }}.zip
files: |
dist-${{ steps.version.outputs.version }}.zip
dist-simple-${{ steps.version.outputs.version }}.zip
generate_release_notes: true
draft: false
prerelease: false
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lerna-debug.log*

node_modules
dist
dist-simple
dist-ssr
*.local
.npm-cache
Expand Down Expand Up @@ -41,4 +42,4 @@ libreoffice-wasm-package
bentopdf-*.tgz

# test
dist-test
dist-test
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import eslintConfigPrettier from "eslint-config-prettier";

export default [
{ files: ["**/*.{js,mjs,cjs,ts}"] },
{ ignores: ["dist/**", "coverage/**", "node_modules/**", "**/.vitepress/cache/**", "public/**/*.min.js"] },
{ ignores: ["dist/**", "dist-simple/**", "coverage/**", "node_modules/**", "**/.vitepress/cache/**", "public/**/*.min.js"] },
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
Expand Down
17 changes: 10 additions & 7 deletions scripts/package-dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import { execSync } from 'child_process';
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const version = packageJson.version;

console.log(`📦 Building dist folder for version ${version}...`);
const buildOutputDirName = process.env.BUILD_OUTPUT_DIR || 'dist';
console.log(`📦 Building ${buildOutputDirName} folder for version ${version}...`);

const isSimpleMode = (buildOutputDirName === "dist-simple") ? true : false;

// Run the build command
try {
execSync('npm run build', { stdio: 'inherit' });
execSync(`SIMPLE_MODE=${isSimpleMode} npm run build`, { stdio: 'inherit' });
Comment on lines +14 to +18
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify how SIMPLE_MODE is consumed (truthy/presence vs strict comparison).
rg -nP --type=ts --type=js -C3 'process\.env\.SIMPLE_MODE|SIMPLE_MODE'

Repository: alam00000/bentopdf

Length of output: 3454


Fix cross-platform env variable passing in build command.

The inline SIMPLE_MODE=${isSimpleMode} npm run build syntax does not work on Windows shells. Use the env option in execSync instead for cross-platform compatibility. Also simplify the unnecessary ternary operator.

Proposed fix
-const isSimpleMode = (buildOutputDirName === "dist-simple") ? true : false;
+const isSimpleMode = buildOutputDirName === 'dist-simple';

 try {
-  execSync(`SIMPLE_MODE=${isSimpleMode} npm run build`, { stdio: 'inherit' });
+  execSync('npm run build', {
+    stdio: 'inherit',
+    env: {
+      ...process.env,
+      ...(isSimpleMode ? { SIMPLE_MODE: 'true' } : {}),
+    },
+  });
   console.log('✅ Build completed successfully');
 } catch (error) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isSimpleMode = (buildOutputDirName === "dist-simple") ? true : false;
// Run the build command
try {
execSync('npm run build', { stdio: 'inherit' });
execSync(`SIMPLE_MODE=${isSimpleMode} npm run build`, { stdio: 'inherit' });
const isSimpleMode = buildOutputDirName === 'dist-simple';
// Run the build command
try {
execSync('npm run build', {
stdio: 'inherit',
env: {
...process.env,
...(isSimpleMode ? { SIMPLE_MODE: 'true' } : {}),
},
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/package-dist.js` around lines 14 - 18, Replace the unnecessary
ternary for isSimpleMode with a boolean assignment and stop inlining environment
variables in the shell command; instead set SIMPLE_MODE via the execSync env
option. Specifically, update the isSimpleMode declaration (currently named
isSimpleMode) to a simple boolean and change the execSync call that runs `npm
run build` to pass an env object (merging process.env) with SIMPLE_MODE set to
the boolean/string value so the command is cross-platform compatible on Windows
and Unix.

console.log('✅ Build completed successfully');
} catch (error) {
console.error('❌ Build failed:', error.message);
Expand All @@ -25,12 +28,12 @@ import { pipeline } from 'stream';
import { promisify } from 'util';
import archiver from 'archiver';

const distDir = path.resolve('./dist');
const zipPath = path.resolve(`./dist-${version}.zip`);
const buildOutputDir = path.resolve(`./${buildOutputDirName}`);
const zipPath = path.resolve(`./${buildOutputDirName}-${version}.zip`);

// Check if dist directory exists
if (!existsSync(distDir)) {
console.error('❌ dist directory does not exist. Please run build first.');
if (!existsSync(buildOutputDir)) {
console.error(`❌ ${buildOutputDirName} directory does not exist. Please run build first.`);
process.exit(1);
}

Expand All @@ -55,7 +58,7 @@ archive.on('error', (err) => {
archive.pipe(output);

// Append the dist directory to the archive
archive.directory(distDir, false);
archive.directory(buildOutputDir, false);

// Finalize the archive
archive.finalize();
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@
}
},
"include": ["src", "src/**/*.ts", "public/workers", "vite.config.ts"], // Updated to include all TS files
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "dist", "dist-simple"]
}
9 changes: 6 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function createLanguageMiddleware(isDev: boolean): Connect.NextHandleFunction {

const basePath = getBasePath();
const [fullPathname, queryString] = req.url.split('?');
const outputDir = process.env.BUILD_OUTPUT_DIR || 'dist';

let pathname = fullPathname;
if (basePath && basePath !== '/' && pathname.startsWith(basePath)) {
Expand Down Expand Up @@ -114,7 +115,7 @@ function createLanguageMiddleware(isDev: boolean): Connect.NextHandleFunction {
if (isDev) {
req.url = '/index.html' + (queryString ? `?${queryString}` : '');
} else {
const langIndexPath = resolve(__dirname, 'dist', lang, 'index.html');
const langIndexPath = resolve(__dirname, outputDir, lang, 'index.html');
if (fs.existsSync(langIndexPath)) {
req.url =
`/${lang}/index.html` + (queryString ? `?${queryString}` : '');
Expand Down Expand Up @@ -142,7 +143,7 @@ function createLanguageMiddleware(isDev: boolean): Connect.NextHandleFunction {
} else {
const langPagePath = resolve(
__dirname,
'dist',
outputDir,
lang,
`${pageName}.html`
);
Expand All @@ -162,7 +163,7 @@ function createLanguageMiddleware(isDev: boolean): Connect.NextHandleFunction {
} else {
const langPagePath = resolve(
__dirname,
'dist',
outputDir,
lang,
`${cleanPath}.html`
);
Expand Down Expand Up @@ -367,6 +368,7 @@ export default defineConfig(() => {
},
},
build: {
outDir: process.env.BUILD_OUTPUT_DIR || 'dist',
rollupOptions: {
input: {
main:
Expand Down Expand Up @@ -582,6 +584,7 @@ export default defineConfig(() => {
'*.config.ts',
'**/*.d.ts',
'dist/',
'dist-simple/',
],
},
},
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineConfig({
'node_modules/',
'src/tests/',
'dist/',
'dist-simple/',
'*.config.ts',
'*.config.js',
'**/*.d.ts',
Expand Down
Loading