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

Improve ESM support by using import with file extensions #302

Open
wants to merge 73 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a32b402
fix: ESM by using import with file extensions
JumpLink Jul 12, 2022
d3a040f
fix: Fix jest config to allow .js extensions
JumpLink Jul 12, 2022
983bec6
fix: Fix angular webpack config to allow .js extensions
JumpLink Jul 12, 2022
1c8f7b0
fix: Add custom angular webpack config for api-console-guiFix to allo…
JumpLink Jul 13, 2022
2cfedb4
Merge branch 'master' into esm-extension-import
JumpLink Jul 18, 2022
f31e5c8
Merge branch 'master' into esm-extension-import
JumpLink Jul 18, 2022
02041ea
chore: Lint import file extensions
JumpLink Jul 18, 2022
fac976b
chore: New lint:ext npm script
JumpLink Jul 18, 2022
47f3679
Merge branch 'esm-extension-import' into lint-file-extension
JumpLink Jul 18, 2022
6208747
Merge master into lint-file-extension
JumpLink Jul 19, 2022
3f11d2b
Merge master into esm-extension-import
JumpLink Jul 19, 2022
4671f8a
Merge branch 'esm-extension-import' into lint-file-extension
JumpLink Jul 19, 2022
527dc84
Merge branch 'master' into esm-extension-import
JumpLink Jul 19, 2022
ee66dda
fix(rpc-tests): Fix import MemoryLoggerTransport
JumpLink Jul 19, 2022
c79d567
Merge branch 'master' into esm-extension-import
JumpLink Jul 19, 2022
0c77420
Merge branch 'esm-extension-import' into lint-file-extension
JumpLink Jul 19, 2022
4451660
fix: ESM imports for api-console-gui
JumpLink Jul 19, 2022
5741844
fix: Fix require and __dirname for ESM
JumpLink Jul 19, 2022
276f7e2
chore(example-app): Move from CJS to ESM
JumpLink Jul 19, 2022
ac0b8d6
Merge branch 'esm-extension-import' of github.com:gjsify/deepkit-fram…
JumpLink Jul 19, 2022
6dbfc39
chore(example-app): Add support for ESM and CJS
JumpLink Jul 19, 2022
75f27fa
chore: Moved getDirname to @deepkit/core
JumpLink Jul 19, 2022
f4b9b66
Merge branch 'master' into esm-extension-import
JumpLink Jul 19, 2022
d6772eb
chore(esm): Add Node.js independent __dirname implementation
JumpLink Jul 20, 2022
de393a7
fix: Fix jsx and test by removing jsx.Fragment
JumpLink Jul 20, 2022
f8bdd4e
fix: Invalid json in packages/example-app/tsconfig.json
JumpLink Jul 20, 2022
9e201b8
fix: ng build deprecated --prod warning
JumpLink Jul 20, 2022
295417c
Merge branch 'esm-extension-import' into lint-file-extension
JumpLink Jul 20, 2022
4cd70d1
fix: Try to fix jsx and test by set jsx.Fragment to undefined
JumpLink Jul 20, 2022
94b460e
feat(platform): Initial new package
JumpLink Jul 22, 2022
ef262b2
chore(platform): Make use of the new platform package
JumpLink Jul 22, 2022
3e14209
chore(github): Add github action workflows for the new platform package
JumpLink Jul 22, 2022
bf2fa23
fix(platform): Add platform as dependency
JumpLink Jul 22, 2022
7ce435c
Merge remote-tracking branch 'upstream/master' into esm-extension-import
JumpLink Jul 22, 2022
9d54527
chore(github): Use npm ci instead of npm install
JumpLink Jul 22, 2022
10ac9d5
chore(github): Use bootstrap:ci instead of bootstrap
JumpLink Jul 22, 2022
c4e495a
chore(github): Update package-lock.json
JumpLink Jul 22, 2022
e406f7e
fix(framework): Install @deepkit/platform as a default dependency (no…
JumpLink Jul 22, 2022
211b68f
chore(github): Platform tests: Only run bootstrap:ci for @deepkit/pla…
JumpLink Jul 22, 2022
7b5ed00
chore(github): Platform tests: Also run bootstrap:ci for @deepkit/typ…
JumpLink Jul 22, 2022
29fafc5
chore(github): Platform tests: Do not link the packages (platform has…
JumpLink Jul 22, 2022
6cecae4
Merge branch 'master' into esm-extension-import
JumpLink Jul 25, 2022
09a5055
Merge branch 'esm-extension-import' into lint-file-extension
JumpLink Jul 25, 2022
64394ab
fix(github): Run build:platform before install-compiler
JumpLink Jul 25, 2022
90077b9
fix(lint): Fix new lint errors
JumpLink Jul 25, 2022
8c51a09
fix(lint): Fix lint workflow
JumpLink Jul 25, 2022
445f402
fix(github): Fix workflows
JumpLink Jul 25, 2022
a213a33
fix(platform): Fix build npm script
JumpLink Jul 25, 2022
36c8ab5
fix(ci): Build platform before run install-compiler
JumpLink Jul 25, 2022
f91b2fc
fix(type-compiler): Do not use @deepkit/platform
JumpLink Jul 25, 2022
55da098
fix(github): Fix workflows again
JumpLink Jul 25, 2022
7d1eeb0
fix(github): Only bootstrap @deepkit/platform
JumpLink Jul 25, 2022
ee97022
fix(platform): Do not run clear before build to fix build on windows
JumpLink Jul 25, 2022
aaf5335
fix(platform): Add browser test assets to repo for faster tests
JumpLink Jul 25, 2022
28302c5
fix(ci): Build platform before build anything else
JumpLink Jul 25, 2022
c9ff3ba
fix(ci): Fix platform build by allow just the default tsc command
JumpLink Jul 25, 2022
49b1c77
chore(platform): Platform structure adapted to skeleton + add referen…
JumpLink Jul 25, 2022
58fe7eb
Merge branch 'master' into esm-extension-import
JumpLink Jul 26, 2022
bf52d15
fix(test): Fix imports in tests
JumpLink Jul 26, 2022
8d21b31
fix(tests): Downgrade typescript from 4.7.4 to 4.6.2 again
JumpLink Jul 27, 2022
b084236
fix(tests): Downgrade typescript from 4.7.4 to 4.6.2 again (package-l…
JumpLink Jul 27, 2022
23f37b1
chore(tsconfig): Update tsconfig files using sync-tsconfig-deps.js
JumpLink Jul 27, 2022
c2c8721
fix: Import of typescript
JumpLink Jul 28, 2022
44e0c71
Merge remote-tracking branch 'upstream/master' into esm-extension-import
JumpLink Jul 28, 2022
3f0ac2a
chore(github): Move all new workflows into main.yml
JumpLink Jul 28, 2022
e0b4e08
chore(core) Removed getCurrentFileName method
JumpLink Jul 29, 2022
83eeaf6
chore: Revert DEVELOPMENT.md
JumpLink Jul 31, 2022
e2a9e2f
Merge branch 'master' into esm-extension-import
JumpLink Aug 2, 2022
31b1dad
chore(platform): Bump version 1.0.1-alpha.75
JumpLink Aug 8, 2022
3ccf85b
Merge branch 'master' into esm-extension-import
JumpLink Aug 8, 2022
c331fed
fix: New issues after master merge
JumpLink Aug 8, 2022
764d69f
Merge branch 'master' into esm-extension-import
JumpLink Aug 24, 2022
52b99bc
chore(platform): Add platform as a dependency to more packages of the…
JumpLink Aug 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
124 changes: 124 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ on:
push:

jobs:

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: npm install
run: npm ci
- name: Check import file extensions
run: npm run lint:ext

unit-tests:
runs-on: buildjet-2vcpu-ubuntu-2004
strategy:
Expand Down Expand Up @@ -345,3 +360,112 @@ jobs:
# run: cd packages/benchmark && sh setup.sh
# - name: Benchmark run
# run: cd packages/benchmark && npm run benchmark

platform-browser:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Install NPM dependencies
run: npm ci
- name: Bootstrap
run: npm run bootstrap:ci -- --scope @deepkit/platform
# - name: Link
# run: npm run link
# - name: Install compiler
# run: npm run install-compiler
- name: Build Platform
run: npm run lerna -- build --scope="@deepkit/platform"
- name: Test
run: npm run lerna -- test:browser --scope="@deepkit/platform"

platform-deno:
strategy:
matrix:
node-version: [ 16.x]
deno-version: [ vx.x.x ]
os:
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Setup Deno
uses: denolib/setup-deno@v2
with:
deno-version: ${{ matrix.deno-version }}
- name: Install NPM dependencies
run: npm ci
- name: Bootstrap
run: npm run bootstrap:ci -- --scope @deepkit/platform
# - name: Link
# run: npm run link
# - name: Install compiler
# run: npm run install-compiler
- name: Build Platform
run: npm run lerna -- build --scope="@deepkit/platform"
- name: Test
run: npm run lerna -- test:deno --scope="@deepkit/platform"

platform-gjs:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Install GJS
run: sudo apt-get --yes install gjs
- name: Install NPM dependencies
run: npm ci
- name: Bootstrap
run: npm run bootstrap:ci -- --scope @deepkit/platform
# - name: Link
# run: npm run link
# - name: Install compiler
# run: npm run install-compiler
- name: Build Platform
run: npm run lerna -- build --scope="@deepkit/platform"
- name: Test
run: npm run lerna -- test:gjs --scope="@deepkit/platform"

platform-node:
strategy:
matrix:
node-version: [ 16.x ]
os:
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install NPM dependencies
run: npm ci
- name: Bootstrap
run: npm run bootstrap:ci -- --scope @deepkit/platform
# - name: Link
# run: npm run link
# - name: Install compiler
# run: npm run install-compiler
- name: Build Platform
run: npm run lerna -- build --scope="@deepkit/platform"
- name: Test
run: npm run lerna -- test:node --scope="@deepkit/platform"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ coverage
packages/node
packages/network
packages/*/dist/*
!packages/*/dist/esm/
packages/*/dist/esm/*
!packages/*/dist/esm/package.json
!packages/*/dist/.gitkeep
packages/benchmark/src/orm/end-to-end/sqlite/prisma.sqlite
Expand All @@ -13,3 +15,4 @@ packages/benchmark/results
packages/example-app/var/debug
packages/example-app/migrations
.vs
packages/platform/test/browser/base.test.js
74 changes: 74 additions & 0 deletions lint-file-extension.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const path = require('path');
const fs = require('fs/promises');

const search = async (dir, regex, ext, exclude) => {
const files = await getFiles(dir, ext, exclude);
const result = [];

for (file of files) {
const content = await fs.readFile(file, 'utf8');

if (regex.test(content)) {
result.push(file);
}
};

return result;
}

/**
*
* @param {string} dir
* @param {string} ext
* @param {string[]} excludes
* @returns
*/
const getFiles = async (dir, ext, excludes) => {
let files = [];

if(excludes.find(exclude => dir.includes(exclude))) {
console.debug("exclude", dir)
return files;
}

const stat = await fs.lstat(dir);
if (!stat.isDirectory()) {
return files;
}

const dirFiles = await fs.readdir(dir);

for (let file of dirFiles) {
const filePath = path.join(dir, file);

if(excludes.find(exclude => filePath.includes(exclude))) {
continue
}

const stat = await fs.lstat(filePath);

if (stat.isDirectory()) {
const nestedFiles = await getFiles(filePath, ext, excludes);
files = files.concat(nestedFiles);
} else if (stat.isFile()) {
if (path.extname(file) === ext) {
files.push(filePath);
}
}
};

return files;
}

search('./packages', /(import|from) ("|')\..*(?<!.js)("|')/g, '.ts', ['dist', 'node_modules', 'compiler.spec.ts', 'mod.ts']).then((files)=> {
if(files.length) {
console.error(`Imports without file extension found!`);
console.error('\t' + files.join('\n\t'));
process.exit(1);
}
console.info("All imports are looking good :)");
process.exit(0);

}).catch((error) => {
console.error(error);
})
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"private": true,
"scripts": {
"test": "node --max_old_space_size=3048 node_modules/jest/bin/jest.js --forceExit --no-cache",
"lerna": "lerna run",
"test:coverage": "node --max_old_space_size=3048 node_modules/jest/bin/jest.js --coverage --forceExit --no-cache",
"bootstrap": "lerna bootstrap --no-ci",
"bootstrap:ci": "lerna bootstrap --ignore @deepkit/benchmark",
Expand All @@ -22,7 +23,8 @@
"docs": "rm -rf docs && node --max-old-space-size=12096 node_modules/.bin/typedoc packages/*/index.ts",
"publish": "lerna publish --no-private prerelease",
"publish-force": "npm run build && lerna publish --no-private --force-publish",
"publish-website": "heroku container:push web && heroku container:release web"
"publish-website": "heroku container:push web && heroku container:release web",
"lint:ext": "node lint-file-extension.cjs"
},
"peerDependencies": {},
"devDependencies": {
Expand All @@ -46,6 +48,9 @@
"node": ">= 14.0.0"
},
"jest": {
"moduleNameMapper": {
"(.+)\\.js": "$1"
},
"resolver": "./jest-resolver.js",
"testPathIgnorePatterns": [
"packages/*/dist"
Expand Down
4 changes: 2 additions & 2 deletions packages/angular-universal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
* You should have received a copy of the MIT License along with this program.
*/

export * from './src/listener';
export * from './src/module';
export * from './src/listener.js';
export * from './src/module.js';
export { HttpResponse, HttpRequest } from '@deepkit/http';
2 changes: 1 addition & 1 deletion packages/angular-universal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/angular-universal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
"@deepkit/type": "^1.0.1-alpha.75",
"@types/node": "^14.0.0"
},
"jest": {
"jest": {
"moduleNameMapper": {
"(.+)\\.js": "$1"
},
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/angular-universal/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import { HtmlResponse, httpWorkflow, RouteConfig } from '@deepkit/http';
import { eventDispatcher } from '@deepkit/event';
import { Logger } from '@deepkit/logger';
import { Config } from './config';
import { Config } from './config.js';
import { join } from 'path';
import { readFileSync } from 'fs';
import type { Router } from '@angular/router';
import { AngularUniversalModule } from './module';
import { AngularUniversalModule } from './module.js';

export class AngularUniversalListener {
protected serverModule: any;
Expand Down
4 changes: 2 additions & 2 deletions packages/angular-universal/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/

import { createModule } from '@deepkit/app';
import { AngularUniversalListener } from './listener';
import { Config } from './config';
import { AngularUniversalListener } from './listener.js';
import { Config } from './config.js';

export class AngularUniversalModule extends createModule({
config: Config,
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-universal/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
"path": "../type/tsconfig.json"
}
]
}
}
2 changes: 1 addition & 1 deletion packages/api-console-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
* You should have received a copy of the MIT License along with this program.
*/

export * from './src/api';
export * from './src/api.js';
5 changes: 4 additions & 1 deletion packages/api-console-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
"@deepkit/rpc": "^1.0.1-alpha.75",
"@deepkit/type": "^1.0.1-alpha.75"
},
"jest": {
"jest": {
"moduleNameMapper": {
"(.+)\\.js": "$1"
},
"testEnvironment": "node",
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
Expand Down
17 changes: 16 additions & 1 deletion packages/api-console-api/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@
"module": "ES2020"
},
"references": [
{
"path": "../bson/tsconfig.esm.json"
},
{
"path": "../core/tsconfig.esm.json"
},
{
"path": "../crypto/tsconfig.json"
},
{
"path": "../injector/tsconfig.esm.json"
},
{
"path": "../logger/tsconfig.esm.json"
},
{
"path": "../rpc/tsconfig.esm.json"
},
{
"path": "../type/tsconfig.esm.json"
}
]
}
}
Loading