Skip to content

Commit

Permalink
Vite works for node?
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Feb 9, 2024
1 parent b2ac186 commit 8484ff9
Show file tree
Hide file tree
Showing 11 changed files with 662 additions and 189 deletions.
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
23 changes: 12 additions & 11 deletions packages/addon-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,28 @@
"author": "Edward Faulkner <[email protected]>",
"type": "module",
"bin": {
"addon-dev": "./src/commands.js"
"addon-dev": "./dist/commands.js"
},
"exports": {
"./template-colocation-plugin": "./src/template-colocation-plugin.js",
"./rollup": "./src/rollup.js"
"./template-colocation-plugin": "./dist/template-colocation-plugin.js",
"./rollup": "./dist/rollup.js"
},
"files": [
"sample-rollup.config.js",
"src/**/*.js",
"src/**/*.d.ts",
"src/**/*.js.map"
"dist",
"declarations"
],
"scripts": {
"prepack": "tsc",
"build": "tsc",
"prepack": "vite build",
"build": "vite build",
"test": "jest"
},
"dependencies": {
"@embroider/core": "workspace:^",
"@rollup/pluginutils": "^4.1.1",
"@rollup/pluginutils": "^5.1.0",
"content-tag": "^1.1.2",
"execa": "^8.0.1",
"fix-bad-declaration-output": "^1.0.3",
"fix-bad-declaration-output": "^1.1.2",
"fs-extra": "^10.0.0",
"minimatch": "^3.0.4",
"rollup-plugin-copy-assets": "^2.0.3",
Expand All @@ -52,7 +51,9 @@
"@types/yargs": "^17.0.3",
"rollup": "^3.23.0",
"tmp": "^0.1.0",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vite-plugin-dts": "^3.7.2"
},
"engines": {
"node": "12.* || 14.* || >= 16"
Expand Down
6 changes: 3 additions & 3 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 { join } from 'node:path';
import yargs from 'yargs/yargs';
import type { Argv } from 'yargs';

Expand All @@ -25,7 +25,7 @@ yargs(process.argv.slice(2))
'link-test-app',
'Ensures that a test app (that lives a subdir under an addon) has access to the addon and all appropriate deps',
(yargs) => commonArgs(yargs),
function (opts) {
function(opts) {
let { testAppDir, addonDir } = opts;
ensureSymlinkSync(
join(addonDir, 'node_modules', '.bin'),
Expand Down Expand Up @@ -53,7 +53,7 @@ yargs(process.argv.slice(2))
default: false,
});
},
function (opts) {
function(opts) {
let { testAppDir, addonDir, lint } = opts;
let addonPkg = readJSONSync(join(addonDir, 'package.json'));
let testPkg = readJSONSync(join(testAppDir, 'package.json'));
Expand Down
2 changes: 1 addition & 1 deletion 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 { 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
2 changes: 1 addition & 1 deletion packages/addon-dev/src/rollup-glint-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function rollupGlintPlugin(pattern: string): Plugin {
* 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(`pnpm glint --declaration`, { stdio: 'inherit' });
await execaCommand(`glint --declaration`, { stdio: 'inherit', preferLocal: true });
/**
* https://github.com/microsoft/TypeScript/issues/56571#
* README: https://github.com/NullVoxPopuli/fix-bad-declaration-output
Expand Down
4 changes: 2 additions & 2 deletions packages/addon-dev/src/rollup-hbs-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createFilter } from '@rollup/pluginutils';
import type { Plugin, PluginContext, CustomPluginOptions } from 'rollup';
import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';
import { hbsToJS } from '@embroider/core';
import { parse as pathParse } from 'path';
import { parse as pathParse } from 'node:path';

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-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
35 changes: 35 additions & 0 deletions packages/addon-dev/vite.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { resolve } from 'node:path';
import url from 'node:url';

import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

export default defineConfig({
build: {
outDir: 'dist',
target: ['es2021'],
ssr: true, // aka, "node mode"
minify: false,
sourcemap: true,
lib: {
entry: [
resolve(__dirname, 'src/rollup.ts'),
resolve(__dirname, 'src/template-colocation-plugin.ts'),
resolve(__dirname, 'src/commands.ts'),
],
name: '@embroider/addon-dev',
formats: ['es'],
},
rollupOptions: {
external: ['@embroider/core']
},
},
plugins: [
dts({
rollupTypes: true,
outDir: 'declarations',
}),
],
});
Loading

0 comments on commit 8484ff9

Please sign in to comment.