Skip to content

Commit

Permalink
Merge pull request #975 from EhTagTranslation/esm
Browse files Browse the repository at this point in the history
Upgrade to ESM
  • Loading branch information
OpportunityLiu authored Jun 20, 2022
2 parents 76a7c65 + 63cfb04 commit e05d0e3
Show file tree
Hide file tree
Showing 104 changed files with 615 additions and 473 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
/dist
/db
/scripts
*.config.js
*.config.{js,ts}
.*.{js,ts}
/test/

# packages
/node_modules/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ github.event.head_commit.message }}
tag: v${{ env.PACKAGE_VERSION}}
tag: v${{ env.PACKAGE_VERSION }}
commit: ${{ github.sha }}
artifacts: ./release.zip
allowUpdates: true
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lerna-debug.log*
.DS_Store

# Tests
/coverage
coverage/
/.nyc_output

# IDEs and editors
Expand Down
7 changes: 5 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"eh-tag-editor": {
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"builder": "@angular-builders/custom-webpack:browser",
"configurations": {
"production": {
"budgets": [
Expand Down Expand Up @@ -36,6 +36,9 @@
}
},
"options": {
"customWebpackConfig": {
"path": "./angular.webpack.config.js"
},
"allowedCommonJsDependencies": ["markdown-it", "linkify-it", "parse5", "axios", "validator"],
"assets": ["src/browser/favicon.ico", "src/browser/favicon.svg", "src/browser/assets"],
"buildOptimizer": false,
Expand All @@ -59,7 +62,7 @@
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"builder": "@angular-builders/custom-webpack:dev-server",
"configurations": {
"production": {
"browserTarget": "eh-tag-editor:build:production"
Expand Down
16 changes: 16 additions & 0 deletions angular.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-check
import ResolveTypeScriptPlugin from 'resolve-typescript-plugin';

/**
*
* @param {import('webpack').Configuration} config
* @param {import('@angular-builders/custom-webpack').CustomWebpackBrowserSchema} options
* @param {import('@angular-builders/custom-webpack').TargetOptions} targetOptions
* @returns {import('webpack').Configuration}
*/
export default function (config, options, targetOptions) {
config.resolve ??= {};
config.resolve.plugins ??= [];
config.resolve.plugins.push(new ResolveTypeScriptPlugin());
return config;
}
1 change: 0 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"entryFile": "server/main",
"compilerOptions": {
"deleteOutDir": true,
"plugins": [{ "name": "@nestjs/swagger/plugin" }],
"tsConfigPath": "src/server/tsconfig.json"
}
}
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "eh-tag-editor",
"version": "1.0.0",
"version": "2.0.0",
"type": "module",
"engines": {
"node": "16",
"yarn": "1.22"
},
"scripts": {
"start:server": "nest start --debug --watch",
"build:server": "nest build",
"test:server": "jest --config ./src/server/jest.config.js --coverage",
"test:server": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --config ./test/server/jest.config.js",
"heroku-postbuild": "yarn build:server && yarn test:server && node scripts/server.js",
"start:tool": "yarn build:tool --watch",
"build:tool": "tsc --project ./src/tool",
Expand All @@ -25,6 +26,9 @@
"browser": {
"./src/shared/ehentai/http/config.ts": "./src/shared/ehentai/http/config.browser.ts"
},
"imports": {
"#*": "./dist/*.js"
},
"private": true,
"dependencies": {
"@actions/core": "~1.9.0",
Expand All @@ -38,12 +42,11 @@
"@octokit/auth-oauth-app": "~4.3.1",
"@octokit/rest": "~18.12.0",
"axios": "~0.27.2",
"bluebird": "~3.7.2",
"class-transformer": "~0.5.1",
"class-validator": "~0.13.2",
"cli-color": "~2.0.2",
"commander": "~9.3.0",
"escape-string-regexp": "~4.0.0",
"escape-string-regexp": "~5.0.0",
"fastify-swagger": "~5.2.0",
"fs-extra": "~10.1.0",
"idb-keyval": "~6.1.0",
Expand All @@ -53,15 +56,16 @@
"markdown-it": "~13.0.1",
"node-cache": "~5.1.2",
"pako": "~2.0.4",
"parse5": "~6.0.0",
"parse5": "~7.0.0",
"proxy-agent": "^5.0.0",
"reflect-metadata": "~0.1.13",
"rxjs": "~7.5.5",
"simple-git": "~3.7.1",
"simple-git": "~3.8.0",
"source-map-support": "~0.5.21",
"tslib": "~2.4.0"
},
"devDependencies": {
"@angular-builders/custom-webpack": "^14.0.0",
"@angular-devkit/build-angular": "^14.0.2",
"@angular/animations": "^14.0.2",
"@angular/cdk": "^14.0.2",
Expand All @@ -79,7 +83,6 @@
"@nestjs/cli": "~8.2.6",
"@nestjs/schematics": "~8.0.11",
"@nestjs/testing": "~8.4.7",
"@types/bluebird-global": "~3.5.13",
"@types/cli-color": "~2.0.2",
"@types/fs-extra": "~9.0.13",
"@types/jest": "~28.1.2",
Expand All @@ -92,12 +95,14 @@
"@types/supertest": "~2.0.12",
"@typescript-eslint/eslint-plugin": "~5.28.0",
"@typescript-eslint/parser": "~5.28.0",
"cross-env": "^7.0.3",
"eslint": "~8.18.0",
"eslint-config-prettier": "~8.5.0",
"eslint-plugin-prettier": "~4.0.0",
"jest": "~28.1.1",
"jest-to-match-shape-of": "~1.3.2",
"prettier": "~2.7.1",
"resolve-typescript-plugin": "^1.2.0",
"rimraf": "~3.0.2",
"supertest": "~6.2.3",
"ts-jest": "~28.0.5",
Expand Down
7 changes: 4 additions & 3 deletions scripts/info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const fs = require('fs-extra');
const { exportVariable } = require('@actions/core');
// @ts-check
import fs from 'fs-extra';
import { exportVariable } from '@actions/core';

/** @type {import('type-fest').PackageJson} */
const packageJson = fs.readJSONSync('./package.json');
const packageJson = await fs.readJSON('./package.json');
exportVariable('PACKAGE_VERSION', packageJson.version);
exportVariable('PACKAGE_NAME', packageJson.name);
7 changes: 4 additions & 3 deletions scripts/server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const fs = require('fs-extra');
// @ts-check
import fs from 'fs-extra';

const removedPackages = ['lazysizes', 'zone.js'];
const removedPackageHeaders = ['@angular', 'angular', '@actions/'];

/** @type {import('type-fest').PackageJson} */
const packageJson = fs.readJSONSync('./package.json');
const packageJson = await fs.readJSON('./package.json');
packageJson.scripts = {
start: 'node dist/server/main.js',
};
Expand All @@ -14,4 +15,4 @@ for (const key in packageJson.dependencies) {
packageJson.dependencies[key] = undefined;
}
}
fs.writeJSONSync('./package.json', packageJson);
await fs.writeJSON('./package.json', packageJson);
25 changes: 18 additions & 7 deletions scripts/tool.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
const fs = require('fs-extra');
// @ts-check
import fs from 'fs-extra';

const removedPackages = ['lazysizes', 'zone.js'];
const removedPackageHeaders = ['@angular', 'angular', '@nestjs/', 'fastify'];

/** @type {import('type-fest').PackageJson} */
const packageJson = fs.readJSONSync('./package.json');
packageJson.scripts = {
start: 'node ./index.js',
};
const packageJson = await fs.readJSON('./package.json');
packageJson.scripts = undefined;
packageJson.devDependencies = undefined;
for (const key in packageJson.dependencies) {
if (removedPackageHeaders.some((leading) => key.startsWith(leading)) || removedPackages.includes(key)) {
packageJson.dependencies[key] = undefined;
}
}
fs.writeJSONSync('./dist/package.json', packageJson);
fs.writeFileSync('./dist/index.js', 'require("./tool")');
for (const key in packageJson.imports) {
const value = packageJson.imports[key];
if (typeof value == 'string') {
packageJson.imports[key] = value.replace(/^.\/dist\//, './');
}
}
for (const key in /** @type {object} */ (packageJson.exports)) {
const value = packageJson.exports[key];
if (typeof value == 'string') {
packageJson.exports[key] = value.replace(/^.\/dist\//, './');
}
}
await fs.writeJSON('./dist/package.json', packageJson);
await fs.writeFile('./dist/index.js', 'import "./tool/index.js";');
4 changes: 2 additions & 2 deletions src/browser/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { EhTagConnectorService } from 'browser/services/eh-tag-connector.service';
import { EhTagConnectorService } from '#browser/services/eh-tag-connector.service';
import { Location } from '@angular/common';
import { DbRepoService } from 'browser/services/db-repo.service';
import { DbRepoService } from '#browser/services/db-repo.service';

@Component({
selector: 'app-root',
Expand Down
4 changes: 2 additions & 2 deletions src/browser/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import { EditorComponent } from './editor/editor.component';
import { GithubCornerComponent } from './github-corner/github-corner.component';
import { MarkPipe } from './shared/pipe/mark.pipe';
import { LinkifyPipe } from './shared/pipe/linkify.pipe';
import { TitleService } from 'browser/services/title.service';
import { ehHttpInterceptorProvider } from 'browser/services/eh-http-interceptor';
import { TitleService } from '#browser/services/title.service';
import { ehHttpInterceptorProvider } from '#browser/services/eh-http-interceptor';

@NgModule({
declarations: [
Expand Down
2 changes: 1 addition & 1 deletion src/browser/app/editor.can-activate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, UrlTree, Router } from '@angular/router';
import { parseNamespace } from 'shared/namespace';
import { parseNamespace } from '#shared/namespace';

@Injectable()
export class CanActivateEditor implements CanActivate {
Expand Down
30 changes: 15 additions & 15 deletions src/browser/app/editor/editor.component.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Component, OnInit } from '@angular/core';
import { EhTagConnectorService } from 'browser/services/eh-tag-connector.service';
import { RouteService } from 'browser/services/route.service';
import { EhTagConnectorService } from '#browser/services/eh-tag-connector.service';
import { RouteService } from '#browser/services/route.service';
import { Observable, BehaviorSubject, combineLatest, merge, lastValueFrom } from 'rxjs';
import { editableNs, ETKey } from 'browser/interfaces/ehtranslation';
import { editableNs, ETKey } from '#browser/interfaces/ehtranslation';
import { MatSnackBar } from '@angular/material/snack-bar';
import { FormControl, Validators, FormGroup, AbstractControl, ValidationErrors } from '@angular/forms';
import { map, tap, mergeMap, filter, shareReplay, debounceTime, distinctUntilChanged } from 'rxjs/operators';
import { TitleService } from 'browser/services/title.service';
import { GithubOauthService } from 'browser/services/github-oauth.service';
import { TitleService } from '#browser/services/title.service';
import { GithubOauthService } from '#browser/services/github-oauth.service';
import { trigger, state, style, transition, animate } from '@angular/animations';
import { snackBarConfig } from 'browser/environments/environment';
import { Tag, NamespaceName, FrontMatters } from 'shared/interfaces/ehtag';
import { GithubReleaseService } from 'browser/services/github-release.service';
import { DebugService } from 'browser/services/debug.service';
import { DbRepoService } from 'browser/services/db-repo.service';
import { RawTag, isRawTag } from 'shared/raw-tag';
import { isNamespaceName } from 'shared/namespace';
import { Context } from 'shared/markdown';
import { suggestTag, Tag as TagSuggest } from 'shared/ehentai';
import { namespaceMapToSearch, parseTag, tagAbbrFull } from 'shared/tag';
import { snackBarConfig } from '#browser/environments/environment';
import { Tag, NamespaceName, FrontMatters } from '#shared/interfaces/ehtag';
import { GithubReleaseService } from '#browser/services/github-release.service';
import { DebugService } from '#browser/services/debug.service';
import { DbRepoService } from '#browser/services/db-repo.service';
import { RawTag, isRawTag } from '#shared/raw-tag';
import { isNamespaceName } from '#shared/namespace';
import { Context } from '#shared/markdown';
import { suggestTag, Tag as TagSuggest } from '#shared/ehentai';
import { namespaceMapToSearch, parseTag, tagAbbrFull } from '#shared/tag';

class TagSuggestOption {
constructor(
Expand Down
12 changes: 6 additions & 6 deletions src/browser/app/list/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import type { SortDirection } from '@angular/material/sort';
import type { Params } from '@angular/router';
import { Observable, Subject, combineLatest, BehaviorSubject, from } from 'rxjs';
import { map, tap, shareReplay, debounceTime, filter, mergeMap } from 'rxjs/operators';
import type { NamespaceName, Tag, RepoData } from 'shared/interfaces/ehtag';
import { isNamespaceName } from 'shared/namespace';
import type { NamespaceName, Tag, RepoData } from '#shared/interfaces/ehtag';
import { isNamespaceName } from '#shared/namespace';
import { regexFromSearch } from '../shared/pipe/mark.pipe';
import { editableNs, ETKey } from '../../interfaces/ehtranslation';
import { RouteService } from 'browser/services/route.service';
import { DebugService } from 'browser/services/debug.service';
import { TitleService } from 'browser/services/title.service';
import { GithubReleaseService } from 'browser/services/github-release.service';
import { RouteService } from '#browser/services/route.service';
import { DebugService } from '#browser/services/debug.service';
import { TitleService } from '#browser/services/title.service';
import { GithubReleaseService } from '#browser/services/github-release.service';

export interface ETItem extends Tag<'raw'>, ETKey {}

Expand Down
6 changes: 3 additions & 3 deletions src/browser/app/user/user.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { GithubOauthService } from 'browser/services/github-oauth.service';
import type { GithubUser } from 'browser/interfaces/github';
import { GithubReleaseService } from 'browser/services/github-release.service';
import { GithubOauthService } from '#browser/services/github-oauth.service';
import type { GithubUser } from '#browser/interfaces/github';
import { GithubReleaseService } from '#browser/services/github-release.service';
import { finalize } from 'rxjs/operators';

@Component({
Expand Down
2 changes: 1 addition & 1 deletion src/browser/interfaces/ehtranslation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NamespaceName } from 'shared/interfaces/ehtag';
import type { NamespaceName } from '#shared/interfaces/ehtag';

export interface ETKey {
raw: string;
Expand Down
5 changes: 0 additions & 5 deletions src/browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import Bluebird from 'bluebird';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
Expand All @@ -12,10 +11,6 @@ async function main(): Promise<void> {
enableProdMode();
}
await platformBrowserDynamic().bootstrapModule(AppModule);

const bluebirdPatchSymbol = Zone.__symbol__('bluebird') as keyof ZoneType;
const bluebirdPatch = Zone[bluebirdPatchSymbol] as (b: typeof Bluebird) => void;
bluebirdPatch(Bluebird);
}

main().catch((err) => console.error(err));
1 change: 0 additions & 1 deletion src/browser/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
*/

import 'zone.js'; // Included with Angular CLI.
import 'zone.js/plugins/zone-bluebird';

/***************************************************************************************************
* APPLICATION IMPORTS
Expand Down
2 changes: 1 addition & 1 deletion src/browser/services/cache.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RepoData } from 'shared/interfaces/ehtag';
import type { RepoData } from '#shared/interfaces/ehtag';
import { Injectable } from '@angular/core';
import * as idb from 'idb-keyval';

Expand Down
10 changes: 5 additions & 5 deletions src/browser/services/database.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
FrontMatters,
RepoData,
RepoInfo,
} from 'shared/interfaces/ehtag';
import type { DatabaseView, NamespaceDatabaseView } from 'shared/interfaces/database';
import { Context } from 'shared/markdown';
import type { RawTag } from 'shared/raw-tag';
import { TagRecord } from 'shared/tag-record';
} from '#shared/interfaces/ehtag';
import type { DatabaseView, NamespaceDatabaseView } from '#shared/interfaces/database';
import { Context } from '#shared/markdown';
import type { RawTag } from '#shared/raw-tag';
import { TagRecord } from '#shared/tag-record';

const fallback: Record<NamespaceName, Omit<FrontMatters, 'key'>> = {
rows: { name: '行名', description: '标签列表的行名,即标签的命名空间。' },
Expand Down
2 changes: 1 addition & 1 deletion src/browser/services/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TagType, RepoData } from 'shared/interfaces/ehtag';
import type { TagType, RepoData } from '#shared/interfaces/ehtag';
import type { CacheService } from './cache.service';
import { DatabaseInMemory as DatabaseInMemoryBase } from './database.shared';

Expand Down
Loading

0 comments on commit e05d0e3

Please sign in to comment.