Skip to content

Commit

Permalink
Merge pull request #2227 from embroider-build/merge-stable
Browse files Browse the repository at this point in the history
Merge stable into main
  • Loading branch information
ef4 authored Jan 14, 2025
2 parents e73d3a7 + 5893216 commit f779011
Show file tree
Hide file tree
Showing 21 changed files with 2,046 additions and 1,469 deletions.
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
# Embroider Changelog

## Release (2025-01-07)

@embroider/compat 3.8.0 (minor)
@embroider/core 3.5.0 (minor)

#### :rocket: Enhancement
* `@embroider/compat`, `@embroider/core`, `@embroider/test-scenarios`
* [#2210](https://github.com/embroider-build/embroider/pull/2210) Deprecate staticHelpers, staticModifiers, and staticComponents in favour of staticInvokables ([@mansona](https://github.com/mansona))

#### Committers: 1
- Chris Manson ([@mansona](https://github.com/mansona))

## Release (2024-12-20)

@embroider/webpack 4.0.9 (patch)

#### :bug: Bug Fix
* `@embroider/webpack`
* [#2220](https://github.com/embroider-build/embroider/pull/2220) Set MiniCssExtractPlugin ignoreOrder to true for default config ([@lfloyd117](https://github.com/lfloyd117))

#### Committers: 1
- Liam Floyd ([@lfloyd117](https://github.com/lfloyd117))

## Release (2024-12-19)

@embroider/addon-dev 7.1.1 (patch)

#### :bug: Bug Fix
* `@embroider/addon-dev`
* [#2217](https://github.com/embroider-build/embroider/pull/2217) Fix declarations plugin to cover import() ([@simonihmig](https://github.com/simonihmig))

#### Committers: 1
- Simon Ihmig ([@simonihmig](https://github.com/simonihmig))

## Release (2024-12-16)

@embroider/addon-dev 7.1.0 (minor)
@embroider/compat 3.7.1 (patch)
@embroider/core 3.4.20 (patch)
@embroider/macros 1.16.10 (patch)

#### :rocket: Enhancement
* `@embroider/addon-dev`
* [#2200](https://github.com/embroider-build/embroider/pull/2200) Add rollup declarations plugin ([@simonihmig](https://github.com/simonihmig))

#### :house: Internal
* `@embroider/sample-transforms`, `@embroider/test-fixtures`, `@embroider/test-scenarios`
* [#2204](https://github.com/embroider-build/embroider/pull/2204) Fix stable ([@simonihmig](https://github.com/simonihmig))
* `@embroider/macros`
* [#2201](https://github.com/embroider-build/embroider/pull/2201) Fix type error on stable ([@simonihmig](https://github.com/simonihmig))

#### Committers: 1
- Simon Ihmig ([@simonihmig](https://github.com/simonihmig))

## Release (2024-11-11)

@embroider/addon-dev 7.0.0 (major)
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ You can pass options into Embroider by passing them into the `compatBuild` funct
return require('@embroider/compat').compatBuild(app, Webpack, {
// staticAddonTestSupportTrees: true,
// staticAddonTrees: true,
// staticHelpers: true,
// staticModifiers: true,
// staticComponents: true,
// staticInvokables: true,
// staticEmberSource: true,
// splitAtRoutes: ['route.name'], // can also be a RegExp
// packagerOptions: {
Expand All @@ -99,9 +97,8 @@ The recommended steps when introducing Embroider into an existing app are:

1. First make it work with no options. This is the mode that supports maximum backward compatibility. If you're hitting errors, first look at the "Compatibility with Classic Builds" section below.
2. Enable `staticAddonTestSupportTrees` and `staticAddonTrees` and test your application. This is usually safe, because most code in these trees gets consumed via `import` statements that we can analyze. But you might find exceptional cases where some code is doing a more dynamic thing.
3. Enable `staticHelpers` and `staticModifiers` and test. This is usually safe because addon helpers and modifiers get invoked declaratively in templates and we can see all invocations.
4. Enable `staticComponents`, and work to eliminate any resulting build warnings about dynamic component invocation. You may need to add `packageRules` that declare where invocations like `{{component someComponent}}` are getting `someComponent` from.
5. Once your app is working with all of the above, you can enable `splitAtRoutes` and add the `@embroider/router` and code splitting should work. See the packages/router/README.md for details and limitations.
3. Enable `staticInvokables` and work to eliminate any resulting build warnings about dynamic component invocation. You may need to add `packageRules` that declare where invocations like `{{component someComponent}}` are getting `someComponent` from.
4. Once your app is working with all of the above, you can enable `splitAtRoutes` and add the `@embroider/router` and code splitting should work. See the packages/router/README.md for details and limitations.

## Configuring asset URLs

Expand Down
6 changes: 6 additions & 0 deletions packages/addon-dev/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testEnvironment: 'node',
testMatch: [
'<rootDir>/tests/**/*.test.js',
],
};
9 changes: 7 additions & 2 deletions packages/addon-dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/addon-dev",
"version": "7.0.0",
"version": "7.1.1",
"description": "Utilities for addon authors",
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,6 +37,7 @@
"@embroider/core": "workspace:^",
"@rollup/pluginutils": "^5.1.0",
"content-tag": "^3.0.0",
"execa": "^5.1.1",
"fs-extra": "^10.0.0",
"minimatch": "^3.0.4",
"rollup-plugin-copy-assets": "^2.0.3",
Expand All @@ -46,11 +47,15 @@
"devDependencies": {
"@embroider/test-support": "workspace:*",
"@glimmer/syntax": "^0.84.2",
"@glint/core": "^1.5.0",
"@glint/template": "^1.5.0",
"@glint/environment-ember-loose": "^1.5.0",
"@glint/environment-ember-template-imports": "^1.5.0",
"@types/fs-extra": "^9.0.12",
"@types/minimatch": "^3.0.4",
"@types/yargs": "^17.0.3",
"rollup": "^3.23.0",
"tmp": "^0.1.0",
"scenario-tester": "^4.0.0",
"typescript": "^5.4.5"
},
"engines": {
Expand Down
54 changes: 54 additions & 0 deletions packages/addon-dev/src/rollup-declarations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import execa from 'execa';
import walkSync from 'walk-sync';
import { readFile, writeFile } from 'fs/promises';

export default function rollupDeclarationsPlugin(declarationsDir: string) {
let glintPromise: Promise<void>;

return {
name: 'glint-dts',
buildStart: () => {
const runGlint = async () => {
await execa('glint', ['--declaration'], {
stdio: 'inherit',
preferLocal: true,
});

await fixDeclarationsInMatchingFiles(declarationsDir);
};

// We just kick off glint here early in the rollup process, without making rollup wait for this to finish, by not returning the promise
// The output of this is not relevant to further stages of the rollup build, this is just happening in parallel to other rollup compilation
glintPromise = runGlint();
},

// Make rollup wait for glint to have finished before calling the build job done
writeBundle: () => glintPromise,
};
}

async function fixDeclarationsInMatchingFiles(dir: string) {
const dtsFiles = walkSync(dir, {
globs: ['**/*.d.ts'],
directories: false,
includeBasePath: true,
});

return Promise.all(
dtsFiles.map(async (file) => {
const content = await readFile(file, { encoding: 'utf8' });

await writeFile(file, fixDeclarations(content));
})
);
}

// Strip any .gts extension from imports in d.ts files, as these won't resolve. See https://github.com/typed-ember/glint/issues/628
// Once Glint v2 is available, this shouldn't be needed anymore.
function fixDeclarations(content: string) {
return content
.replace(/from\s+'([^']+)\.gts'/g, `from '$1'`)
.replace(/from\s+"([^"]+)\.gts"/g, `from '$1'`)
.replace(/import\("([^"]+)\.gts"\)/g, `import('$1')`)
.replace(/import\('([^']+)\.gts'\)/g, `import('$1')`);
}
5 changes: 5 additions & 0 deletions packages/addon-dev/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { default as gjs } from './rollup-gjs-plugin';
import { default as publicEntrypoints } from './rollup-public-entrypoints';
import { default as appReexports } from './rollup-app-reexports';
import { default as keepAssets } from './rollup-keep-assets';
import { default as declarations } from './rollup-declarations';
import { default as dependencies } from './rollup-addon-dependencies';
import {
default as publicAssets,
Expand Down Expand Up @@ -109,4 +110,8 @@ export class Addon {
publicAssets(path: string, opts?: PublicAssetsOptions) {
return publicAssets(path, opts);
}

declarations(path: string) {
return declarations(path);
}
}
119 changes: 119 additions & 0 deletions packages/addon-dev/tests/declarations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
'use strict';

import rollupDeclarationsPlugin from '../src/rollup-declarations';
import { Project } from 'scenario-tester';
import { rollup } from 'rollup';
import { readFile } from 'fs-extra';
import { join } from 'path';

const projectBoilerplate = {
'tsconfig.json': JSON.stringify({
include: ['src/**/*'],
compilerOptions: {
target: 'es2022',
module: 'esnext',
declaration: true,
declarationDir: 'declarations',
emitDeclarationOnly: true,
rootDir: './src',
allowImportingTsExtensions: true,
},
glint: {
environment: ['ember-loose', 'ember-template-imports'],
},
}),
};

async function generateProject(src: {}): Promise<Project> {
const project = new Project('my-addon', {
files: {
...projectBoilerplate,
src,
},
});
project.linkDevDependency('typescript', { baseDir: __dirname });
project.linkDevDependency('@glint/core', { baseDir: __dirname });
project.linkDevDependency('@glint/template', { baseDir: __dirname });
project.linkDevDependency('@glint/environment-ember-loose', {
baseDir: __dirname,
});
project.linkDevDependency('@glint/environment-ember-template-imports', {
baseDir: __dirname,
});

await project.write();

return project;
}

async function runRollup(dir: string, rollupOptions = {}) {
const currentDir = process.cwd();
process.chdir(dir);

try {
const bundle = await rollup({
input: './src/index.ts',
plugins: [rollupDeclarationsPlugin('declarations')],
...rollupOptions,
});

await bundle.write({ format: 'esm', dir: 'dist' });
} finally {
process.chdir(currentDir);
}
}

describe('declarations', function () {
let project: Project | null;

afterEach(() => {
project?.dispose();
project = null;
});

test('it generates dts output', async function () {
project = await generateProject({
'index.ts': 'export default 123',
});

await runRollup(project.baseDir);

expect(
await readFile(join(project.baseDir, 'declarations/index.d.ts'), {
encoding: 'utf8',
})
).toContain('export default');
});

test('it has correct imports', async function () {
project = await generateProject({
'index.ts': `
import foo from './foo.gts';
import bar from './bar.gts';
import baz from './baz.ts';
export { foo, bar, baz };
export class Foo {
bar = import('./bar.gts')
}
`,
'foo.gts': 'export default 123',
'bar.gts': 'export default 234',
'baz.ts': 'export default 345',
});

await runRollup(project.baseDir);

const output = await readFile(
join(project.baseDir, 'declarations/index.d.ts'),
{
encoding: 'utf8',
}
);

expect(output).toContain(`import foo from './foo';`);
expect(output).toContain(`import bar from './bar';`);
expect(output).toContain(`import baz from './baz.ts';`);
expect(output).toContain(`import('./bar')`);
});
});
2 changes: 1 addition & 1 deletion packages/compat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/compat",
"version": "3.7.0",
"version": "3.8.0",
"private": false,
"description": "Backward compatibility layer for the Embroider build system.",
"repository": {
Expand Down
Loading

0 comments on commit f779011

Please sign in to comment.