Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js/web] fix package export for bundlers #23257

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

fs-eire
Copy link
Contributor

@fs-eire fs-eire commented Jan 6, 2025

Description

This PR tries to fix #22615. (see detailed description in the issue)

A perfect solution would be too difficult to make, because there are a huge number of combinations of usage scenarios, including combinations of development framework, bundler, dev/prod mode, and so on.

This PR is using the following approach:

  • Introduce a new type of end to end test: export test. This type of tests are complete web apps that use popular web development frameworks, and the tests are using puppeteer to run the apps and check if the apps can run without error.
    • added one nextjs based web app and one vite based web app.
  • In the test, perform the following test steps:
    • npm install for packages built locally
    • npm run dev to start dev server and use puppeteer to launch the browser to test
    • npm run build && npm run start to test prod build and use puppeteer to launch the browser to test
  • Make changes to ort-web, including:
    • special handling on Webpack's behavior of rewriting import.meta.url to a file:// string
    • revise build definitions
    • fix wasm URL for proxy, if used in a bundled build

@fs-eire fs-eire marked this pull request as ready for review January 6, 2025 09:47
@fs-eire fs-eire requested review from Copilot and guschmue January 6, 2025 09:48
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 30 out of 45 changed files in this pull request and generated 5 comments.

Files not reviewed (15)
  • js/web/test/e2e/exports/testcases/nextjs-default/.gitignore: Language not supported
  • js/web/test/e2e/exports/testcases/nextjs-default/app/globals.css: Language not supported
  • js/web/test/e2e/exports/testcases/nextjs-default/app/page.module.css: Language not supported
  • js/web/test/e2e/exports/testcases/nextjs-default/jsconfig.json: Language not supported
  • js/web/test/e2e/exports/testcases/nextjs-default/package.json: Language not supported
  • js/web/test/e2e/exports/testcases/nextjs-default/components/onnx-helper.js: Evaluated as low risk
  • js/web/test/e2e/exports/testcases/nextjs-default/components/onnx-test-bar.js: Evaluated as low risk
  • js/web/test/e2e/exports/testcases/nextjs-default/app/page.js: Evaluated as low risk
  • js/web/lib/backend-wasm.ts: Evaluated as low risk
  • js/web/lib/wasm/wasm-factory.ts: Evaluated as low risk
  • js/web/test/e2e/exports/README.md: Evaluated as low risk
  • js/web/lib/wasm/proxy-wrapper.ts: Evaluated as low risk
  • js/web/script/build.ts: Evaluated as low risk
  • js/web/test/e2e/exports/testcases/nextjs-default/app/layout.js: Evaluated as low risk
  • js/web/test/e2e/exports/testcases/nextjs-default/next.config.mjs: Evaluated as low risk
Comments suppressed due to low confidence (5)

js/web/test/e2e/exports/testcases/nextjs-default.md:15

  • [nitpick] The term 'App Router' should be 'app router' to match the casing used in the rest of the document.
√ Would you like to use App Router? (recommended) ... No

js/web/test/e2e/exports/main.js:30

  • Ensure that the ANSI escape codes for colored output are intentional and correctly handled in environments that might not support them.
await runDevTest('vite-default', '\x1b[32m➜\x1b[39m  \x1b[1mLocal\x1b[22m:', 5173);

js/web/test/e2e/exports/main.js:31

  • Ensure that the ANSI escape codes for colored output are intentional and correctly handled in environments that might not support them.
await runProdTest('vite-default', '\x1b[32m➜\x1b[39m  \x1b[1mLocal\x1b[22m:', 4173);

js/web/lib/wasm/wasm-utils-import.ts:1

  • The preload function should have an explicit return type defined for better readability and maintainability.
preload = async (absoluteUrl: string): Promise<string> => {

js/web/lib/wasm/wasm-utils-import.ts:12

  • [nitpick] The error handling in the normalizeUrl function should provide more context to help with debugging.
normalizeUrl = (filename: string, prefixOverride?: string) => {

js/web/test/e2e/exports/testcases/nextjs-default.md Outdated Show resolved Hide resolved
await page.waitForSelector('#ortstate', { visible: true });
// if multi-thread is enabled, check the checkbox
if (multiThread) {
await page.locator('#cb-mt').click();
Copy link
Preview

Copilot AI Jan 6, 2025

Choose a reason for hiding this comment

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

The method 'page.locator' is not valid in Puppeteer. Use 'page.$' or 'page.$eval' instead.

Suggested change
await page.locator('#cb-mt').click();
await (await page.$('#cb-mt')).click();

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The method 'page.locator' is not valid in Puppeteer. Use 'page.$' or 'page.$eval' instead.

Seems like a false statement. page.locator() works well in this test and there is also API reference for the function:
https://pptr.dev/guides/page-interactions#locators

js/web/test/e2e/exports/test.js Show resolved Hide resolved
js/web/test/e2e/exports/test.js Show resolved Hide resolved
js/web/test/e2e/exports/test.js Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Web] Feature Request: workaround for bundlers when using onnxruntime-web
1 participant