Skip to content

Commit

Permalink
build: convert commonjs packages to esm (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts authored Nov 22, 2023
1 parent b57bce0 commit af53d8a
Show file tree
Hide file tree
Showing 64 changed files with 246 additions and 140 deletions.
5 changes: 5 additions & 0 deletions apps/analog-app-e2e-cypress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "analog-app-e2e-cypress",
"private": true,
"type": "commonjs"
}
5 changes: 5 additions & 0 deletions apps/analog-app-e2e-playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "analog-app-e2e-playwright",
"private": true,
"type": "commonjs"
}
5 changes: 1 addition & 4 deletions apps/analog-app-e2e-playwright/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { offsetFromRoot } from '@nx/devkit';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
Expand All @@ -12,9 +11,7 @@ export default defineConfig(({ mode }) => {
environment: 'node',
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot(
'apps/analog-app-e2e-playwright'
)}/node_modules/.vitest/analog-app-e2e-playwright`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
2 changes: 1 addition & 1 deletion apps/analog-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
]
}
},
"test": {
"tests": {
"executor": "@nx/vite:test",
"outputs": ["{projectRoot}/coverage"]
}
Expand Down
5 changes: 1 addition & 4 deletions apps/analog-preset-e2e/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { offsetFromRoot } from '@nx/devkit';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
Expand All @@ -12,9 +11,7 @@ export default defineConfig(({ mode }) => {
environment: 'node',
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot(
'apps/analog-preset-e2e'
)}/node_modules/.vitest/analog-preset-e2e`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
5 changes: 5 additions & 0 deletions apps/astro-app-e2e-playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "astro-app-e2e-playwright",
"private": true,
"type": "commonjs"
}
5 changes: 1 addition & 4 deletions apps/astro-app-e2e-playwright/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="vitest" />

import { offsetFromRoot } from '@nx/devkit';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
Expand All @@ -11,9 +10,7 @@ export default defineConfig(({ mode }) => {
environment: 'node',
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot(
'packages/astro-app-e2e-playwright'
)}/node_modules/.vitest/astro-app-e2e-playwright`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
2 changes: 1 addition & 1 deletion apps/blog-app-e2e-cypress/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'cypress';
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset.js';

const cypressJsonConfig = {
fileServerFolder: '.',
Expand Down
5 changes: 5 additions & 0 deletions apps/blog-app-e2e-cypress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "blog-app-e2e-cypress",
"private": true,
"type": "commonjs"
}
9 changes: 9 additions & 0 deletions apps/create-analog-e2e/tests/create-analog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ describe.skip('create-analog e2e', () => {
`${tmpDir}/node_modules/@analogjs`
);

const angularJson = JSON.parse(
readFileSync(`${tmpDir}/angular.json`, 'utf-8')
);
angularJson.projects['my-app'].root = '.';
writeFileSync(
`${tmpDir}/angular.json`,
JSON.stringify(angularJson, null, 2)
);

let viteConfig = readFileSync(`${tmpDir}/vite.config.ts`, 'utf-8');
viteConfig = viteConfig.replace(
'analog()',
Expand Down
5 changes: 1 addition & 4 deletions apps/create-analog-e2e/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { offsetFromRoot } from '@nx/devkit';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
Expand All @@ -12,9 +11,7 @@ export default defineConfig(({ mode }) => {
environment: 'node',
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot(
'apps/create-analog-e2e'
)}/node_modules/.vitest/create-analog-e2e`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
19 changes: 18 additions & 1 deletion apps/nx-plugin-e2e/tests/nx-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import {
copyNodeModules,
runNxCommandAsync,
uniq,
readFile,
updateFile,
renameFile,
} from '@nx/plugin/testing';

describe('nx-plugin e2e', () => {
describe.skip('nx-plugin e2e', () => {
// Setting up individual workspaces per
// test can cause e2e runs to take a long time.
// For this reason, we recommend each suite only
Expand All @@ -30,6 +33,20 @@ describe('nx-plugin e2e', () => {
);
copyNodeModules(['@analogjs']);

const pkJson = JSON.parse(readFile(`package.json`));
pkJson.type = 'module';
updateFile(`package.json`, JSON.stringify(pkJson, null, 2));
renameFile(`${project}/postcss.config.js`, `${project}/postcss.config.cjs`);
renameFile(
`${project}/tailwind.config.js`,
`${project}/tailwind.config.cjs`
);
const postCssConfig = readFile(`${project}/postcss.config.cjs`);
updateFile(
`${project}/postcss.config.cjs`,
postCssConfig.replace('tailwind.config.js', 'tailwind.config.cjs')
);

await runNxCommandAsync(`test ${project}`);

expect(() => checkFilesExist(`${project}/index.html`)).not.toThrow();
Expand Down
5 changes: 1 addition & 4 deletions apps/nx-plugin-e2e/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { offsetFromRoot } from '@nx/devkit';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
Expand All @@ -12,9 +11,7 @@ export default defineConfig(({ mode }) => {
environment: 'node',
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot(
'apps/nx-plugin-e2e'
)}/node_modules/.vitest/nx-plugin-e2e`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
5 changes: 1 addition & 4 deletions apps/trpc-app-e2e-playwright/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { offsetFromRoot } from '@nx/devkit';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
Expand All @@ -12,9 +11,7 @@ export default defineConfig(({ mode }) => {
environment: 'node',
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot(
'apps/trpc-app-e2e-playwright'
)}/node_modules/.vitest/trpc-app-e2e-playwright`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { join } = require('path');
module.exports = {
plugins: {
tailwindcss: {
config: join(__dirname, 'tailwind.config.js'),
config: join(__dirname, 'tailwind.config.cjs'),
},
autoprefixer: {},
},
Expand Down
2 changes: 1 addition & 1 deletion apps/trpc-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"lintFilePatterns": ["apps/trpc-app/**/*.ts", "apps/trpc-app/**/*.html"]
}
},
"test": {
"tests": {
"executor": "@nx/vite:test",
"outputs": ["{projectRoot}/coverage"]
}
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion libs/card/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"tags": [],
"projectType": "library",
"targets": {
"test": {
"tests": {
"executor": "@nx/vite:test"
},
"lint": {
Expand Down
2 changes: 1 addition & 1 deletion libs/top-bar/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sourceRoot": "libs/top-bar/src",
"prefix": "analogjs",
"targets": {
"test": {
"tests": {
"executor": "@nx/vite:test"
},
"lint": {
Expand Down
3 changes: 1 addition & 2 deletions libs/top-bar/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { offsetFromRoot } from '@nx/devkit';
import angular from '@analogjs/vite-plugin-angular';

// https://vitejs.dev/config/
Expand All @@ -15,7 +14,7 @@ export default defineConfig(({ mode }) => {
setupFiles: ['src/test-setup.ts'],
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot('libs/top-bar/src')}/node_modules/.vitest`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "analogjs-platform",
"version": "1.0.0-beta.1",
"license": "MIT",
"type": "module",
"scripts": {
"dev": "nx serve",
"ng": "nx",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro-angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getViteConfiguration(vite?: PluginOptions) {
*
*/
plugins: [
(viteAngular as any).default(vite),
viteAngular(vite),
{
name: '@analogjs/astro-angular-platform-server',
transform(code: string, id: string) {
Expand Down
4 changes: 0 additions & 4 deletions packages/astro-angular/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
root: 'src',
resolve: {
mainFields: ['module'],
},
test: {
globals: true,
environment: 'jsdom',
Expand Down
4 changes: 1 addition & 3 deletions packages/content/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { offsetFromRoot } from '@nx/devkit';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
return {
root: 'src',
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['src/test-setup.ts'],
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot('packages/content/src')}/node_modules/.vitest`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
1 change: 1 addition & 0 deletions packages/create-analog/template-angular-v16/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "my-app",
"version": "0.0.0",
"type": "module",
"private": true,
"engines": {
"node": ">=18.13.0"
Expand Down
3 changes: 1 addition & 2 deletions packages/nx-plugin/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import { offsetFromRoot } from '@nx/devkit';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
Expand All @@ -12,7 +11,7 @@ export default defineConfig(({ mode }) => {
include: ['**/*.spec.ts'],
exclude: ['**/files/**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot('packages/nx-plugin/src')}/node_modules/.vitest`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@analogjs/platform",
"version": "1.0.0-beta.1",
"type": "commonjs",
"type": "module",
"description": "The fullstack meta-framework for Angular",
"author": "Brandon Roberts <[email protected]>",
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions packages/platform/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { platformPlugin } from './lib/platform-plugin';
import { platformPlugin } from './lib/platform-plugin.js';

export { Options } from './lib/options';
export { Options } from './lib/options.js';
export default platformPlugin;
2 changes: 1 addition & 1 deletion packages/platform/src/lib/platform-plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect } from 'vitest';
import { platformPlugin } from './platform-plugin';
import { platformPlugin } from './platform-plugin.js';

vi.mock('@analogjs/vite-plugin-nitro');
vi.mock('./ssr/ssr-build-plugin');
Expand Down
12 changes: 6 additions & 6 deletions packages/platform/src/lib/platform-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Plugin } from 'vite';
import viteNitroPlugin from '@analogjs/vite-plugin-nitro';
import angular from '@analogjs/vite-plugin-angular';

import { Options } from './options';
import { routerPlugin } from './router-plugin';
import { ssrBuildPlugin } from './ssr/ssr-build-plugin';
import { contentPlugin } from './content-plugin';
import { clearClientPageEndpointsPlugin } from './clear-client-page-endpoint';
import { ssrXhrBuildPlugin } from './ssr/ssr-xhr-plugin';
import { Options } from './options.js';
import { routerPlugin } from './router-plugin.js';
import { ssrBuildPlugin } from './ssr/ssr-build-plugin.js';
import { contentPlugin } from './content-plugin.js';
import { clearClientPageEndpointsPlugin } from './clear-client-page-endpoint.js';
import { ssrXhrBuildPlugin } from './ssr/ssr-xhr-plugin.js';

export function platformPlugin(opts: Options = {}): Plugin[] {
const { apiPrefix, ...platformOptions } = {
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"module": "es2020",
"outDir": "../../dist/out-tsc",
"inlineSourceMap": true,
"sourceMap": false,
Expand Down
3 changes: 1 addition & 2 deletions packages/platform/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="vitest" />

import { offsetFromRoot } from '@nx/devkit';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
Expand All @@ -12,7 +11,7 @@ export default defineConfig(({ mode }) => {
setupFiles: ['src/test-setup.ts'],
include: ['**/*.spec.ts'],
cache: {
dir: `${offsetFromRoot('packages/platform/src')}/node_modules/.vitest`,
dir: `../../node_modules/.vitest`,
},
},
define: {
Expand Down
Loading

0 comments on commit af53d8a

Please sign in to comment.