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

Allow importing anything (except v1 addons) via Service Worker #1881

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ vendor/
public/
coverage/
*.ember-try
tests-self/
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:


tests:
name: "Ember Tests"
name: "Browser Tests"
strategy:
matrix:
# os: [ubuntu-latest, macOS-latest, windows-latest]
Expand All @@ -109,7 +109,7 @@ jobs:
echo "NPM: $( npm --version )"
echo "pnpm: $( pnpm --version )"
- name: Test
run: pnpm turbo test:ember
run: pnpm turbo test:chrome test:firefox
env:
CI_BROWSER: ${{ matrix.ci_browser }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# compiled output
dist/
declarations/
__screenshots__/
/tmp/
/out/

Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.18
22
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ignore-scripts = true
####################
auto-install-peers=false
strict-peer-dependents=true
public-hoist-pattern[]=ember-source

################
# Optimizations
Expand Down
5 changes: 3 additions & 2 deletions apps/repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
"scripts": {
"ember:canary": "npx ember-source-channel-url canary --write",
"ember:beta": "npx ember-source-channel-url beta --write",
"build": "ember build --environment=production",
"build:production": "ember build --environment=production",
"lint:types": "glint",
"lint:fix": "pnpm -w exec lint fix",
"start": "ember serve -p 4201",
"start:iframe": "pnpx http-server ./public -i -p 4204",
"test:browserstack": "./scripts/browserstack.sh",
"test:ember": "ember test --test-port 0",
"test:chrome": "CI_BROWSER=Chrome ember test --test-port 0",
"test:firefox": "CI_BROWSER=Firefox ember test --test-port 0",
"lint": "pnpm -w exec lint",
"lint:js": "pnpm -w exec lint js",
"lint:js:fix": "pnpm -w exec lint js:fix",
Expand Down
5 changes: 3 additions & 2 deletions apps/tutorial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
"license": "MIT",
"author": "NullVoxPopuli",
"scripts": {
"build": "ember build --environment=production",
"build:production": "ember build --environment=production",
"lint": "pnpm -w exec lint",
"lint:types": "glint",
"lint:fix": "pnpm -w exec lint fix",
"cf": "cd dist && npx wrangler pages dev --port 42000 ./",
"start": "ember serve",
"test:ember": "ember test --test-port 0",
"test:chrome": "CI_BROWSER=Chrome ember test --test-port 0",
"test:firefox": "CI_BROWSER=Firefox ember test --test-port 0",
"lint:js": "pnpm -w exec lint js",
"lint:js:fix": "pnpm -w exec lint js:fix",
"lint:hbs": "pnpm -w exec lint hbs",
Expand Down
3 changes: 2 additions & 1 deletion dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"directory": "dev"
},
"license": "MIT",
"author": "NullVoxPopuli"
"author": "NullVoxPopuli",
"version": "0.0.0"
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"@glimmer/component": "^2.0.0",
"@ember/test-waiters": "^4.0.0",
"ember-element-helper": "^0.8.5",
"ember-auto-import": "^2.9.0",
"ember-auto-import": "^2.10.0",
"ember-repl": "workspace:*",
"ember-source": ">= 6.0.1",
"ember-source": "^6.1.0-beta.1",
"webpack": ">= 5.92.0",
"array-includes": "npm:@nolyfill/array-includes@^1",
"array.prototype.findlastindex": "npm:@nolyfill/array.prototype.findlastindex@^1",
Expand Down Expand Up @@ -80,7 +80,8 @@
]
},
"patchedDependencies": {
"browserslist-generator": "patches/browserslist-generator.patch"
"browserslist-generator": "patches/browserslist-generator.patch",
"[email protected]": "patches/[email protected]"
}
}
}
3 changes: 2 additions & 1 deletion packages/app-support/limber-ui/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"scripts": {
"lint:fix": "pnpm -w exec lint fix",
"start": "ember serve",
"test:ember": "ember test --test-port 0",
"test:chrome": "CI_BROWSER=Chrome ember test --test-port 0",
"test:firefox": "CI_BROWSER=Firefox ember test --test-port 0",
"lint": "pnpm -w exec lint",
"lint:js": "pnpm -w exec lint js",
"lint:js:fix": "pnpm -w exec lint js:fix",
Expand Down
77 changes: 31 additions & 46 deletions packages/ember-repl/addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,24 @@
"directory": "packages/ember-repl/addon"
},
"license": "MIT",
"type": "module",
"author": "NullVoxPopuli",
"typesVersions": {
"*": {
"test-support": [
"declarations/test-support/index.d.ts"
],
"markdown/parse": [
"./declarations/compile/markdown-to-ember.d.ts"
],
"*": [
"declarations/*",
"declarations/*/index.d.ts"
]
}
},
"exports": {
".": {
"types": "./declarations/index.d.ts",
"default": "./dist/index.js"
},
"./formats/markdown": {
"types": "./declarations/compile/formats/markdown.d.ts",
"default": "./dist/compile/formats/markdown.js"
},
"./formats/hbs": {
"types": "./declarations/compile/formats/hbs.d.ts",
"default": "./dist/compile/formats/hbs.js"
"types": "./declarations/browser/index.d.ts",
"default": "./dist/browser/index.js"
},
"./formats/gjs": {
"types": "./declarations/compile/formats/gjs/index.d.ts",
"default": "./dist/compile/formats/gjs/index.js"
"./workers/compiler": {
"types": "./declarations/compiler-worker/index.d.ts",
"default": "./dist/compiler-worker.js"
},
"./test-support": {
"types": "./declarations/test-support/index.d.ts",
"default": "./dist/test-support/index.js"
"./workers/markdown": {
"types": "./declarations/markdown-worker/index.d.ts",
"default": "./dist/markdown-worker.js"
},
"./__PRIVATE__DO_NOT_USE__": {
"types": "./declarations/__PRIVATE__.d.ts",
"default": "./dist/__PRIVATE__.js"
"./sw": {
"types": "./declarations/service-worker/index.d.ts",
"default": "./dist/service-worker.js"
},
"./addon-main.js": "./addon-main.cjs"
},
Expand All @@ -60,10 +39,12 @@
"addon-main.cjs"
],
"scripts": {
"build": "rollup --config",
"build": "rm -rf dist declarations && concurrently 'pnpm:build:*'",
"build:browser": "rollup --config",
"build:types": "tsc --emitDeclarationOnly --noEmit false",
"start": "pnpm build:browser --watch",
"lint:types": "tsc --noEmit",
"lint:fix": "pnpm -w exec lint fix",
"start": "rollup --config --watch",
"lint": "pnpm -w exec lint",
"lint:package": "pnpm publint",
"lint:js": "pnpm -w exec lint js",
Expand All @@ -76,28 +57,32 @@
"dependencies": {
"@babel/helper-plugin-utils": "^7.25.7",
"@babel/standalone": "^7.25.7",
"@embroider/addon-shim": "1.8.9",
"@ember/test-waiters": "^3.1.0",
"@embroider/addon-shim": "1.9.0",
"@embroider/macros": "1.16.9",
"@rollup/plugin-alias": "^5.1.1",
"babel-import-util": "^3.0.0",
"babel-plugin-ember-template-compilation": "^2.3.0",
"broccoli-file-creator": "^2.1.1",
"change-case": "^5.4.4",
"common-tags": "^1.8.2",
"content-tag": "^3.0.0",
"content-tag": "3.0.0",
"decorator-transforms": "^2.3.0",
"ember-resources": "^7.0.3",
"line-column": "^1.0.2",
"magic-string": "^0.30.6",
"magic-string": "^0.30.14",
"mdast": "^3.0.0",
"parse-static-imports": "^1.1.0",
"rehype-raw": "^6.1.1",
"rehype-stringify": "^9.0.4",
"remark-gfm": "^3.0.1",
"remark-parse": "^10.0.2",
"remark-rehype": "^10.1.0",
"unified": "^10.1.2",
"promise-worker-bi": "^4.1.1",
"register-service-worker": "^1.7.2",
"rehype-raw": "^7.0.0",
"rehype-stringify": "^10.0.1",
"remark-gfm": "^4.0.0",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.1",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0",
"uuid": "^10.0.0",
"uuid": "^11.0.3",
"vfile": "^6.0.1"
},
"devDependencies": {
Expand All @@ -123,6 +108,7 @@
"@nullvoxpopuli/limber-untyped": "workspace:*",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@tsconfig/ember": "^3.0.7",
"@types/babel__core": "^7.20.5",
"@types/babel__standalone": "^7.1.7",
Expand All @@ -135,7 +121,6 @@
"@typescript-eslint/parser": "^8.8.0",
"concurrently": "^9.0.1",
"ember-resources": "^7.0.0",
"ember-source": ">= 6.0.1",
"ember-template-imports": "^4.1.2",
"ember-template-lint": "^6.0.0",
"eslint": "^8.55.0",
Expand Down
123 changes: 96 additions & 27 deletions packages/ember-repl/addon/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,105 @@
import { Addon } from "@embroider/addon-dev/rollup";

import alias from "@rollup/plugin-alias";
import { babel } from "@rollup/plugin-babel";
import cjs from "@rollup/plugin-commonjs";
import { execaCommand } from "execa";
import commonjs from "@rollup/plugin-commonjs";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { defineConfig } from "rollup";

const addon = new Addon({
srcDir: "src",
destDir: "dist",
});

export default defineConfig({
output: addon.output(),
external: ["@glimmer/compiler", "@glimmer/syntax"],
plugins: [
addon.publicEntrypoints(["**/*.js"]),
addon.appReexports([]),
babel({
extensions: [".js", ".gjs", ".ts", ".gts"],
babelHelpers: "bundled",
}),
addon.dependencies(),
// line-column...
cjs(),
addon.keepAssets(["build/**/*"]),
addon.clean(),
const browser = new Addon({ srcDir: "src/browser", destDir: "dist/browser" });
const compiler = new Addon({ srcDir: "src/compiler-worker", destDir: "dist/compiler-worker" });
const sw = new Addon({ srcDir: "src/service-worker", destDir: "dist/service-worker" });

function ember(name) {
return `./node_modules/ember-source/dist/${name}`;
}

function pkg(name) {
return ember(`packages/${name}`);
}

const lookup = {
"@ember/debug": pkg("@ember/debug/index.js"),
"@ember/template-factory": pkg("@ember/template-factory/index.js"),
"@ember/helper": pkg("@ember/helper/index.js"),
"@ember/modifier": pkg("@ember/modifier/index.js"),
"@ember/template-factory": pkg("@ember/template-factory/index.js"),
"@ember/component": pkg("@ember/component/index.js"),
"@ember/component/template-only": pkg("@ember/component/template-only.js"),
// "ember-template-compiler": ember("ember-template-compiler.js"),
};

const output = {
sourcemap: true,
format: "es",
hoistTransitiveImports: false,
// moduleSideEffects: false,
interop: "default",
};

function bundledEmber() {
return alias([
{
async closeBundle() {
await execaCommand("tsc --emitDeclarationOnly --noEmit false", { stdio: "inherit" });
console.info("Declarations built successfully");
find: /(@?ember.+)/,
replacement: "$1",
customResolver(source) {
let result = lookup[source];

return result;
},
},
],
});
]);
}

function worker(input, out) {
return {
input: input,
external: [],
output: {
...output,
inlineDynamicImports: true,
file: out,
},
plugins: [
babel({
extensions: [".js", ".gjs", ".ts", ".gts"],
babelHelpers: "bundled",
}),
bundledEmber(),
nodeResolve(),
// unified>extends
commonjs(),
],
};
}

export default defineConfig([
{
output: browser.output(),
plugins: [
browser.publicEntrypoints(["**/*.js"]),
browser.appReexports(["./services/ember-repl/compiler.js"]),
babel({
extensions: [".js", ".gjs", ".ts", ".gts"],
babelHelpers: "bundled",
}),
browser.dependencies(),
],
},
worker("src/compiler-worker/index.ts", "dist/compiler-worker.js"),
worker("src/markdown-worker/index.ts", "dist/markdown-worker.js"),
{
input: "src/service-worker/index.ts",
output: {
...output,
file: "dist/service-worker.js",
},
plugins: [
babel({
extensions: [".js", ".gjs", ".ts", ".gts"],
babelHelpers: "bundled",
}),
bundledEmber(),
],
},
]);
1 change: 0 additions & 1 deletion packages/ember-repl/addon/src/__PRIVATE__.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/ember-repl/addon/src/browser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Compiled } from './resource.ts';
export { default as Compiler } from './services/ember-repl/compiler.ts';
Loading
Loading