Skip to content

Commit

Permalink
Merge branch 'stable' into no-this-fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Dec 17, 2024
2 parents 21d969d + 0fc9d1e commit d4f32db
Show file tree
Hide file tree
Showing 25 changed files with 376 additions and 55 deletions.
45 changes: 36 additions & 9 deletions .release-plan.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"solution": {
"@embroider/addon-dev": {
"impact": "major",
"oldVersion": "6.0.1",
"newVersion": "7.0.0",
"impact": "minor",
"oldVersion": "7.0.0",
"newVersion": "7.1.0",
"constraints": [
{
"impact": "major",
"reason": "Appears in changelog section :boom: Breaking Change"
"impact": "minor",
"reason": "Appears in changelog section :rocket: Enhancement"
}
],
"pkgJSONPath": "./packages/addon-dev/package.json"
Expand All @@ -22,16 +22,43 @@
"oldVersion": "1.0.1"
},
"@embroider/compat": {
"oldVersion": "3.7.0"
"impact": "patch",
"oldVersion": "3.7.0",
"newVersion": "3.7.1",
"constraints": [
{
"impact": "patch",
"reason": "Has dependency `workspace:*` on @embroider/macros"
}
],
"pkgJSONPath": "./packages/compat/package.json"
},
"@embroider/core": {
"oldVersion": "3.4.19"
"impact": "patch",
"oldVersion": "3.4.19",
"newVersion": "3.4.20",
"constraints": [
{
"impact": "patch",
"reason": "Has dependency `workspace:*` on @embroider/macros"
}
],
"pkgJSONPath": "./packages/core/package.json"
},
"@embroider/hbs-loader": {
"oldVersion": "3.0.3"
},
"@embroider/macros": {
"oldVersion": "1.16.9"
"impact": "patch",
"oldVersion": "1.16.9",
"newVersion": "1.16.10",
"constraints": [
{
"impact": "patch",
"reason": "Appears in changelog section :house: Internal"
}
],
"pkgJSONPath": "./packages/macros/package.json"
},
"@embroider/reverse-exports": {
"oldVersion": "0.1.0"
Expand All @@ -55,5 +82,5 @@
"oldVersion": "4.0.8"
}
},
"description": "## Release (2024-11-11)\n\n@embroider/addon-dev 7.0.0 (major)\n\n#### :boom: Breaking Change\n* `@embroider/addon-dev`\n * [#2166](https://github.com/embroider-build/embroider/pull/2166) Fix gjs/gts sourcemaps -- we accidentally unlocked really good DX ([@NullVoxPopuli](https://github.com/NullVoxPopuli))\n\n#### Committers: 1\n- [@NullVoxPopuli](https://github.com/NullVoxPopuli)\n"
"description": "## Release (2024-12-16)\n\n@embroider/addon-dev 7.1.0 (minor)\n@embroider/compat 3.7.1 (patch)\n@embroider/core 3.4.20 (patch)\n@embroider/macros 1.16.10 (patch)\n\n#### :rocket: Enhancement\n* `@embroider/addon-dev`\n * [#2200](https://github.com/embroider-build/embroider/pull/2200) Add rollup declarations plugin ([@simonihmig](https://github.com/simonihmig))\n\n#### :house: Internal\n* `@embroider/sample-transforms`, `@embroider/test-fixtures`, `@embroider/test-scenarios`\n * [#2204](https://github.com/embroider-build/embroider/pull/2204) Fix stable ([@simonihmig](https://github.com/simonihmig))\n* `@embroider/macros`\n * [#2201](https://github.com/embroider-build/embroider/pull/2201) Fix type error on stable ([@simonihmig](https://github.com/simonihmig))\n\n#### Committers: 1\n- Simon Ihmig ([@simonihmig](https://github.com/simonihmig))\n"
}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Embroider Changelog

## 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
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.0",
"description": "Utilities for addon authors",
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,6 +37,7 @@
"@embroider/core": "workspace:^",
"@rollup/pluginutils": "^4.1.1",
"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
50 changes: 50 additions & 0 deletions packages/addon-dev/src/rollup-declarations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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'`);
}
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 @@ -108,4 +109,8 @@ export class Addon {
publicAssets(path: string, opts?: PublicAssetsOptions) {
return publicAssets(path, opts);
}

declarations(path: string) {
return declarations(path);
}
}
112 changes: 112 additions & 0 deletions packages/addon-dev/tests/declarations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
'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: {
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 };
`,
'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';`);
});
});
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.7.1",
"private": false,
"description": "Backward compatibility layer for the Embroider build system.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/core",
"version": "3.4.19",
"version": "3.4.20",
"private": false,
"description": "A build system for EmberJS applications.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@embroider/macros",
"version": "1.16.9",
"version": "1.16.10",
"private": false,
"description": "Standardized build-time macros for ember apps.",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/tests/babel/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ disabledTest.failing = disabledTest;

export function allModes(fn: CreateModeTests): CreateTests {
return function createTests(transform: Transform) {
for (let mode of ['build-time', 'run-time']) {
for (const mode of ['build-time', 'run-time']) {
describe(mode, function () {
function applyMode(macrosConfig: MacrosConfig) {
if (mode === 'run-time') {
Expand Down
Loading

0 comments on commit d4f32db

Please sign in to comment.