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

Convert @embroider/addon-dev to ESM #1766

Open
wants to merge 13 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
9 changes: 9 additions & 0 deletions packages/addon-dev/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const path = require("path");

module.exports = {
parserOptions: {
project: path.join(__dirname, "tsconfig.json"),
},
};
5 changes: 4 additions & 1 deletion packages/addon-dev/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.
# new compiled output
dist/
declarations/

# compiled output
# old compiled output
/src/**/*.js
/src/**/*.d.ts
/src/**/*.map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
"use strict";

module.exports = {
overrides: [
{
files: '*.{js,ts}',
files: "*.{js,ts}",
options: {
singleQuote: true,
},
Expand Down
18 changes: 18 additions & 0 deletions packages/addon-dev/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"dynamicImport": true,
"privateMethod": true,
"functionBind": true,
"topLevelAwait": true
},
"transform": null,
"target": "es2022",
"loose": false,
"externalHelpers": false
},
"minify": false
}
32 changes: 22 additions & 10 deletions packages/addon-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,34 @@
},
"license": "MIT",
"author": "Edward Faulkner <[email protected]>",
"type": "module",
"bin": {
"addon-dev": "./src/commands.js"
"addon-dev": "./dist/src/commands.js"
},
"exports": {
"./template-colocation-plugin": "./src/template-colocation-plugin.js",
"./rollup": "./src/rollup.js"
"./template-colocation-plugin": {
"types": "./public-types/template-colocation-plugin.d.ts",
"default": "./dist/src/template-colocation-plugin.js"
},
"./rollup": "./dist/src/rollup.js"
},
"files": [
"sample-rollup.config.js",
"src/**/*.js",
"src/**/*.d.ts",
"src/**/*.js.map"
"dist",
"public-types"
],
"scripts": {
"prepack": "pnpm build",
"build": "rm -rf dist && pnpm build:js",
"build:js": "swc ./src -d dist",
"test": "jest"
},
"dependencies": {
"@embroider/core": "workspace:^",
"@rollup/pluginutils": "^4.1.1",
"@rollup/pluginutils": "^5.1.0",
"content-tag": "^2.0.1",
"fs-extra": "^10.0.0",
"execa": "^8.0.1",
"fix-bad-declaration-output": "^1.1.2",
"fs-extra": "^11.2.0",
"minimatch": "^3.0.4",
"rollup-plugin-copy-assets": "^2.0.3",
"rollup-plugin-delete": "^2.0.0",
Expand All @@ -39,8 +46,13 @@
"devDependencies": {
"@embroider/test-support": "workspace:*",
"@glimmer/syntax": "^0.84.2",
"@types/fs-extra": "^9.0.12",
"@swc/cli": "^0.3.9",
"@swc/core": "^1.4.0",
"@tsconfig/ember": "^3.0.3",
"@types/broccoli-funnel": "^3.0.4",
"@types/fs-extra": "^11.0.4",
"@types/minimatch": "^3.0.4",
"@types/node": "^20.11.5",
"@types/yargs": "^17.0.3",
"rollup": "^3.23.0",
"tmp": "^0.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type { Options } from '@embroider/core';

import type { templateColocationPlugin } from '@embroider/core';

export default templateColocationPlugin;
23 changes: 0 additions & 23 deletions packages/addon-dev/sample-babel.config.js
NullVoxPopuli marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

7 changes: 0 additions & 7 deletions packages/addon-dev/sample-babel.config.json

This file was deleted.

49 changes: 0 additions & 49 deletions packages/addon-dev/sample-rollup.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/addon-dev/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import { ensureSymlinkSync, readJSONSync, writeJSONSync } from 'fs-extra';
import { join } from 'path';
import { ensureSymlinkSync, readJSONSync, writeJSONSync } from 'fs-extra/esm';
import { join } from 'node:path';
import yargs from 'yargs/yargs';
import type { Argv } from 'yargs';

Expand Down
9 changes: 6 additions & 3 deletions packages/addon-dev/src/rollup-addon-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { Plugin } from 'rollup';
import { readJsonSync } from 'fs-extra';
import {
import { readJsonSync } from 'fs-extra/esm';
// NOTE: @embroider/core is compiled to CJS, so its own `export * from shared-internals`
// doesn't work how we want (which is what would provide packageName
import eCore from '@embroider/core';
const {
emberVirtualPackages,
emberVirtualPeerDeps,
packageName,
templateCompilationModules,
} from '@embroider/core';
} = eCore;

const compilationModules = new Set(
templateCompilationModules.map((m) => m.module)
Expand Down
4 changes: 2 additions & 2 deletions packages/addon-dev/src/rollup-app-reexports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readJsonSync, writeJsonSync } from 'fs-extra';
import { extname } from 'path';
import { readJsonSync, writeJsonSync } from 'fs-extra/esm';
import { extname } from 'node:path';
import minimatch from 'minimatch';
import type { Plugin } from 'rollup';

Expand Down
2 changes: 1 addition & 1 deletion packages/addon-dev/src/rollup-gjs-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createFilter } from '@rollup/pluginutils';
import type { Plugin } from 'rollup';
import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';
import { Preprocessor } from 'content-tag';

const PLUGIN_NAME = 'rollup-gjs-plugin';
Expand Down
28 changes: 28 additions & 0 deletions packages/addon-dev/src/rollup-glint-plugin.ts
NullVoxPopuli marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Plugin } from 'rollup';
import { execaCommand } from 'execa';
import { fixBadDeclarationOutput } from 'fix-bad-declaration-output';

export default function rollupGlintPlugin(pattern: string): Plugin {
return {
name: 'rollup-glint-plugin',

async closeBundle() {
/**
* Generate the types (these include /// <reference types="ember-source/types"
* but our consumers may not be using those, or have a new enough ember-source that provides them.
*/
await execaCommand(`glint --declaration`, {
stdio: 'inherit',
preferLocal: true,
});
/**
* https://github.com/microsoft/TypeScript/issues/56571#
* README: https://github.com/NullVoxPopuli/fix-bad-declaration-output
*/
await fixBadDeclarationOutput(pattern || 'declarations/**/*.d.ts', [
'TypeScript#56571',
'Glint#628',
]);
},
};
}
11 changes: 8 additions & 3 deletions packages/addon-dev/src/rollup-hbs-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { createFilter } from '@rollup/pluginutils';
import type { Plugin, PluginContext, CustomPluginOptions } from 'rollup';
import { readFileSync } from 'fs';
import { hbsToJS } from '@embroider/core';
import { parse as pathParse } from 'path';
import { readFileSync } from 'node:fs';
import { parse as pathParse } from 'node:path';

// NOTE: @embroider/core is compiled to CJS, so its own `export * from shared-internals`
// doesn't work how we want (which is what would provide packageName
import eCore from '@embroider/core';

const { hbsToJS } = eCore;

export default function rollupHbsPlugin(): Plugin {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/addon-dev/src/rollup-keep-assets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import walkSync from 'walk-sync';
import type { Plugin } from 'rollup';
import { readFileSync } from 'fs';
import { dirname, join, resolve } from 'path';
import { readFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import minimatch from 'minimatch';

export default function keepAssets({
Expand Down
2 changes: 1 addition & 1 deletion packages/addon-dev/src/rollup-public-assets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readJsonSync, writeJsonSync } from 'fs-extra';
import { readJsonSync, writeJsonSync } from 'fs-extra/esm';
import walkSync from 'walk-sync';
import type { Plugin } from 'rollup';

Expand Down
2 changes: 1 addition & 1 deletion packages/addon-dev/src/rollup-public-entrypoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import walkSync from 'walk-sync';
import path from 'path';
import path from 'node:path';
import minimatch from 'minimatch';

import type { Plugin } from 'rollup';
Expand Down
19 changes: 12 additions & 7 deletions packages/addon-dev/src/rollup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { default as hbs } from './rollup-hbs-plugin';
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 hbs } from './rollup-hbs-plugin.js';
import { default as glint } from './rollup-glint-plugin.js';
import { default as gjs } from './rollup-gjs-plugin.js';
import { default as publicEntrypoints } from './rollup-public-entrypoints.js';
import { default as appReexports } from './rollup-app-reexports.js';
import type { Options as DelOptions } from 'rollup-plugin-delete';
import { default as clean } from 'rollup-plugin-delete';
import { default as keepAssets } from './rollup-keep-assets';
import { default as dependencies } from './rollup-addon-dependencies';
import { default as publicAssets } from './rollup-public-assets';
import { default as keepAssets } from './rollup-keep-assets.js';
import { default as dependencies } from './rollup-addon-dependencies.js';
import { default as publicAssets } from './rollup-public-assets.js';
import type { Plugin } from 'rollup';

export class Addon {
Expand Down Expand Up @@ -61,6 +62,10 @@ export class Addon {
return gjs(options);
}

glint(pattern: string) {
return glint(pattern);
}

// By default rollup does not clear the output directory between builds. This
// does that.
clean(options: DelOptions) {
Expand Down
11 changes: 7 additions & 4 deletions packages/addon-dev/src/template-colocation-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {
templateColocationPlugin,
Options as TemplateColocationPluginOptions,
} from '@embroider/core';
import { type Options as TemplateColocationPluginOptions } from '@embroider/core';

export { TemplateColocationPluginOptions as Options };

// NOTE: @embroider/core is compiled to CJS, so its own `export * from shared-internals`
// doesn't work how we want (which is what would provide packageName
import eCore from '@embroider/core';

export const templateColocationPlugin = eCore.templateColocationPlugin;
export default templateColocationPlugin;
32 changes: 32 additions & 0 deletions packages/addon-dev/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"include": ["src/**/*"],
"compilerOptions": {
"target": "ESNext",
"module": "Node16",
"moduleResolution": "Node16",
// Enabling this breaks all dependencies, since
// the types use import, but they are all CJS
// error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
// "verbatimModuleSyntax": true,

"typeRoots": ["types", "node_modules/@types"],
"noEmit": false,
"esModuleInterop": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"allowUnreachableCode": false,
"strict": true,
"skipLibCheck": true,
"useUnknownInCatchVariables": false,

// Only use TS for declarations
// Can't typecheck due to type errors in @embroider/core
// (NestedHooks, beforeAll, etc isn't defined, for example)
"declaration": true,
"declarationDir": "declarations",
"emitDeclarationOnly": true,
}
}
Loading
Loading