forked from analogjs/analog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce @analogjs/platform package for initial support for AP…
…I routes (analogjs#132) Closes analogjs#6
- Loading branch information
1 parent
d2395a6
commit 3e12f62
Showing
21 changed files
with
1,206 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,7 @@ stats.html | |
|
||
**/test-results/ | ||
**/playwright-report/ | ||
**/playwright/.cache/ | ||
**/playwright/.cache/ | ||
|
||
# Nitro | ||
.nitro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'Analog.js is amazing!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# analog-platform | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build analog-platform` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test analog-platform` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@analogjs/platform", | ||
"version": "0.1.0-alpha.0", | ||
"type": "commonjs", | ||
"peerDependencies": { | ||
"nitropack": "^0.5.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/platform/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "node_modules/@analogjs/platform", | ||
"main": "packages/platform/src/index.ts", | ||
"tsConfig": "packages/platform/tsconfig.lib.json", | ||
"assets": ["packages/platform/*.md"] | ||
}, | ||
"configurations": { | ||
"production": { | ||
"tsConfig": "packages/platform/tsconfig.lib.prod.json" | ||
}, | ||
"development": { | ||
"tsConfig": "packages/platform/tsconfig.lib.json" | ||
} | ||
}, | ||
"defaultConfiguration": "production" | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/platform/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "nx:run-commands", | ||
"outputs": ["coverage/packages/platform"], | ||
"options": { | ||
"command": "vitest", | ||
"cwd": "packages/platform" | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { analogPlatform } from './lib/analog-platform-plugin'; | ||
|
||
export default analogPlatform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { analogPlatform } from './analog-platform-plugin'; | ||
|
||
const mockViteDevServer = { | ||
middlewares: { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
use: () => {}, | ||
}, | ||
}; | ||
|
||
describe('analogPlatformVitePlugin', () => { | ||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
it('should work', () => { | ||
expect(analogPlatform({}).name).toEqual('vite-nitro-plugin'); | ||
}); | ||
|
||
it(`should have the route middleware "/api" `, async () => { | ||
// Arrange | ||
const spy = vi.spyOn(mockViteDevServer.middlewares, 'use'); | ||
|
||
// Act | ||
await (analogPlatform({}).configureServer as any)(mockViteDevServer); | ||
|
||
// Assert | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(spy).toHaveBeenCalledWith('/api', expect.anything()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { loadEsmModule } from '@angular-devkit/build-angular/src/utils/load-esm'; | ||
import { NitroConfig } from 'nitropack'; | ||
import { Plugin, ViteDevServer } from 'vite'; | ||
|
||
export function analogPlatform(opts: { nitro?: NitroConfig }): Plugin { | ||
const nitroConfig: NitroConfig = { | ||
rootDir: 'src', | ||
srcDir: 'src/server', | ||
scanDirs: ['src/server'], | ||
output: { | ||
dir: '../dist/server', | ||
...opts.nitro?.output, | ||
}, | ||
}; | ||
return { | ||
name: 'vite-nitro-plugin', | ||
|
||
async configureServer(viteServer: ViteDevServer) { | ||
const { createNitro, createDevServer, build } = await loadEsmModule< | ||
typeof import('nitropack') | ||
>('nitropack'); | ||
|
||
const nitro = await createNitro({ ...nitroConfig, dev: true }); | ||
const server = createDevServer(nitro); | ||
await build(nitro); | ||
viteServer.middlewares.use('/api', await server.app); | ||
console.log( | ||
`\n\nThe '@analogjs/platform' successfully started.\nThe server endpoints are accessible under the "/api"` | ||
); | ||
}, | ||
|
||
async closeBundle() { | ||
const { createNitro, build } = await loadEsmModule< | ||
typeof import('nitropack') | ||
>('nitropack'); | ||
|
||
const nitro = await createNitro({ ...nitroConfig, dev: false }); | ||
await build(nitro); | ||
await nitro.close(); | ||
console.log(`\n\nThe '@analogjs/platform' successfully built.`); | ||
}, | ||
}; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "es2020", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../dist/out-tsc", | ||
"declaration": true, | ||
"types": [] | ||
}, | ||
"include": ["**/*.ts"], | ||
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig.lib.json", | ||
"compilerOptions": { | ||
"declarationMap": false | ||
}, | ||
"angularCompilerOptions": { | ||
"compilationMode": "partial" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["vitest/globals", "node"] | ||
}, | ||
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference types="vitest" /> | ||
|
||
import { offsetFromRoot } from '@nrwl/devkit'; | ||
import { defineConfig } from 'vite'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig(({ mode }) => { | ||
return { | ||
root: 'src', | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
setupFiles: ['test-setup.ts'], | ||
include: ['**/*.spec.ts'], | ||
cache: { | ||
dir: `${offsetFromRoot('packages/platform/src')}/node_modules/.vitest`, | ||
}, | ||
}, | ||
define: { | ||
'import.meta.vitest': mode !== 'production', | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.