Skip to content

Commit efbf8c4

Browse files
authored
chore(workflow): enable bundle (#953)
1 parent 8f6181f commit efbf8c4

File tree

9 files changed

+26
-38
lines changed

9 files changed

+26
-38
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ shrinkwrap.json
9494

9595
# Build outputs
9696
dist
97+
dist-inspect
9798
lib
9899

99100
# Prettier reformats code blocks inside Markdown, which affects rendered output

apps/chrome-extension/rsbuild.config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ export default defineConfig({
5555
copy: [
5656
{ from: './static', to: './' },
5757
{
58-
from: path.resolve(
59-
__dirname,
60-
'../../packages/web-integration/iife-script',
61-
),
58+
from: path.resolve(__dirname, '../../packages/shared/dist-inspect'),
6259
to: 'scripts',
6360
},
6461
{

biome.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"test-data/**",
1515
"**/inject-tp.js",
1616
"dist",
17+
"dist-inspect",
1718
"__ai_responses__",
1819
"ai-data/**",
1920
"**/doc_build",

packages/shared/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist-inspect

packages/shared/modern.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
14
import { defineConfig, moduleTools } from '@modern-js/module-tools';
25

6+
const scriptStr = fs.readFileSync(
7+
path.resolve(__dirname, './dist-inspect/htmlElement.js'),
8+
'utf-8',
9+
);
10+
311
export default defineConfig({
412
plugins: [moduleTools()],
513
buildPreset: 'npm-library',
@@ -22,5 +30,8 @@ export default defineConfig({
2230
dts: {
2331
respectExternal: true,
2432
},
33+
define: {
34+
__HTML_ELEMENT_SCRIPT__: scriptStr,
35+
},
2536
},
2637
});

packages/shared/modern.inspect.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default defineConfig({
1313
htmlElementDebug: 'src/extractor/debug.ts',
1414
},
1515
autoExternal: false,
16-
outDir: 'dist/script',
16+
outDir: 'dist-inspect',
1717
esbuildOptions: (options) => {
1818
options.globalName = 'midscene_element_inspector';
1919
return options;

packages/shared/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
"files": ["dist", "src", "README.md"],
4040
"scripts": {
4141
"dev": "npm run build:watch",
42-
"build": "npm run build:pkg && npm run build:script",
42+
"build": "npm run build:script && npm run build:pkg",
4343
"build:pkg": "modern build -c ./modern.config.ts",
4444
"build:script": "modern build -c ./modern.inspect.config.ts",
45-
"build:watch": "modern build -w --no-clear",
45+
"build:watch": "npm run build:script && modern build -w --no-clear",
4646
"reset": "rimraf ./**/node_modules",
4747
"lint": "modern lint",
4848
"bump": "modern bump",

packages/shared/src/node/fs.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { existsSync, readFileSync } from 'node:fs';
22
import { dirname, join } from 'node:path';
3-
import path from 'node:path';
4-
import { assert, ifInBrowser } from '../utils';
3+
import { ifInBrowser } from '../utils';
4+
5+
declare const __HTML_ELEMENT_SCRIPT__: string;
56

67
interface PkgInfo {
78
name: string;
@@ -61,14 +62,12 @@ export function findNearestPackageJson(dir: string): string | null {
6162
}
6263

6364
export function getElementInfosScriptContent() {
64-
// Get __dirname equivalent in Node.js environment
65-
const currentFilePath = __filename;
66-
const pathDir = findNearestPackageJson(dirname(currentFilePath));
67-
assert(pathDir, `can't find pathDir, with ${dirname}`);
68-
const scriptPath = path.join(pathDir, './dist/script/htmlElement.js');
69-
const elementInfosScriptContent = readFileSync(scriptPath, 'utf-8');
65+
const htmlElementScript = __HTML_ELEMENT_SCRIPT__;
7066

71-
return elementInfosScriptContent;
67+
if (!htmlElementScript) {
68+
throw new Error('HTML_ELEMENT_SCRIPT inject failed.');
69+
}
70+
return htmlElementScript;
7271
}
7372

7473
export async function getExtraReturnLogic(tree = false) {

packages/web-integration/modern.config.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
1-
import fs from 'node:fs';
2-
import path from 'node:path';
31
import { defineConfig, moduleTools } from '@modern-js/module-tools';
42
import { version } from './package.json';
53

6-
// Create directories and copy files
7-
// The file copying functionality in modern.js is not operating correctly.
8-
const files = [
9-
[
10-
'node_modules/@midscene/shared/dist/script/htmlElement.js',
11-
'iife-script/htmlElement.js',
12-
],
13-
[
14-
'node_modules/@midscene/shared/dist/script/htmlElementDebug.js',
15-
'iife-script/htmlElementDebug.js',
16-
],
17-
];
18-
files.forEach(([src, dest]) => {
19-
// Create parent directory if it doesn't exist
20-
const destDir = path.dirname(path.join(__dirname, dest));
21-
fs.mkdirSync(destDir, { recursive: true });
22-
// Copy file
23-
fs.copyFileSync(path.join(__dirname, src), path.join(__dirname, dest));
24-
});
25-
264
export default defineConfig({
275
plugins: [moduleTools()],
286
buildPreset: 'npm-library',

0 commit comments

Comments
 (0)