diff --git a/.eslintrc.json b/.eslintrc.json index f4c4ba2..1fefb3c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,10 +8,9 @@ "plugins": ["import"], "settings": { "import/resolver": { - "alias": { - "map": [ - ["#common", "./src/common"] - ] + "node": {}, + "typescript": { + "project": "." } } }, diff --git a/eslint.rules.json b/eslint.rules.json index f9ab60a..0897809 100644 --- a/eslint.rules.json +++ b/eslint.rules.json @@ -9,6 +9,6 @@ "semi": ["error", "always"], "spaced-comment": ["error", "always"], "import/no-default-export": "error", - "import/no-unresolved": ["error", { "ignore": ["\\/.*\\.js"] }] + "import/no-unresolved": ["error", { "ignore": ["\\/dist-gh-pages\\/.*\\.js"] }] } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7ec1b3c..e725e42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,22 +1,22 @@ { "name": "dist-gh-pages", - "version": "0.3.4", + "version": "0.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "dist-gh-pages", - "version": "0.3.4", + "version": "0.4.0", "dependencies": { - "arg": "5.0.1", "esm": "3.2.25", "gh-pages": "3.2.3", - "module-alias": "2.2.2", - "replace-in-file": "6.3.2" + "replace-in-file": "6.3.2", + "tsconfig-paths": "3.12.0" }, "devDependencies": { "eslint": "8.5.0", - "eslint-import-resolver-alias": "1.1.2", + "eslint-import-resolver-node": "0.3.6", + "eslint-import-resolver-typescript": "2.5.0", "eslint-plugin-import": "2.25.3" } }, @@ -63,8 +63,7 @@ "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", - "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", - "dev": true + "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=" }, "node_modules/acorn": { "version": "8.6.0", @@ -134,11 +133,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/arg": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.1.tgz", - "integrity": "sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==" - }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -509,18 +503,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint-import-resolver-alias": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/eslint-import-resolver-alias/-/eslint-import-resolver-alias-1.1.2.tgz", - "integrity": "sha512-WdviM1Eu834zsfjHtcGHtGfcu+F30Od3V7I9Fi57uhBEwPkjDcii7/yW8jAT+gOhn4P/vOxxNAXbFAKsrrc15w==", - "dev": true, - "engines": { - "node": ">= 4" - }, - "peerDependencies": { - "eslint-plugin-import": ">=1.4.0" - } - }, "node_modules/eslint-import-resolver-node": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz", @@ -540,6 +522,26 @@ "ms": "^2.1.1" } }, + "node_modules/eslint-import-resolver-typescript": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-2.5.0.tgz", + "integrity": "sha512-qZ6e5CFr+I7K4VVhQu3M/9xGv9/YmwsEXrsm3nimw8vWaVHRDrQRp26BgCypTxBp3vUp4o5aVEJRiy0F2DFddQ==", + "dev": true, + "dependencies": { + "debug": "^4.3.1", + "glob": "^7.1.7", + "is-glob": "^4.0.1", + "resolve": "^1.20.0", + "tsconfig-paths": "^3.9.0" + }, + "engines": { + "node": ">=4" + }, + "peerDependencies": { + "eslint": "*", + "eslint-plugin-import": "*" + } + }, "node_modules/eslint-module-utils": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.7.1.tgz", @@ -1407,7 +1409,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", - "dev": true, "dependencies": { "minimist": "^1.2.0" }, @@ -1506,13 +1507,7 @@ "node_modules/minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "node_modules/module-alias": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz", - "integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==" + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "node_modules/ms": { "version": "2.1.2", @@ -1930,7 +1925,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", - "dev": true, "engines": { "node": ">=4" } @@ -2006,7 +2000,6 @@ "version": "3.12.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.12.0.tgz", "integrity": "sha512-e5adrnOYT6zqVnWqZu7i/BQ3BnhzvGbjEjejFXO20lKIKpwTaupkCPgEfv4GZK1IBciJUEhYs3J3p75FdaTFVg==", - "dev": true, "dependencies": { "@types/json5": "^0.0.29", "json5": "^1.0.1", @@ -2215,8 +2208,7 @@ "@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", - "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", - "dev": true + "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=" }, "acorn": { "version": "8.6.0", @@ -2262,11 +2254,6 @@ "color-convert": "^2.0.1" } }, - "arg": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.1.tgz", - "integrity": "sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==" - }, "argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -2554,13 +2541,6 @@ "v8-compile-cache": "^2.0.3" } }, - "eslint-import-resolver-alias": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/eslint-import-resolver-alias/-/eslint-import-resolver-alias-1.1.2.tgz", - "integrity": "sha512-WdviM1Eu834zsfjHtcGHtGfcu+F30Od3V7I9Fi57uhBEwPkjDcii7/yW8jAT+gOhn4P/vOxxNAXbFAKsrrc15w==", - "dev": true, - "requires": {} - }, "eslint-import-resolver-node": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz", @@ -2582,6 +2562,19 @@ } } }, + "eslint-import-resolver-typescript": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-2.5.0.tgz", + "integrity": "sha512-qZ6e5CFr+I7K4VVhQu3M/9xGv9/YmwsEXrsm3nimw8vWaVHRDrQRp26BgCypTxBp3vUp4o5aVEJRiy0F2DFddQ==", + "dev": true, + "requires": { + "debug": "^4.3.1", + "glob": "^7.1.7", + "is-glob": "^4.0.1", + "resolve": "^1.20.0", + "tsconfig-paths": "^3.9.0" + } + }, "eslint-module-utils": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.7.1.tgz", @@ -3214,7 +3207,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", - "dev": true, "requires": { "minimist": "^1.2.0" } @@ -3291,13 +3283,7 @@ "minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "module-alias": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/module-alias/-/module-alias-2.2.2.tgz", - "integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==" + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "ms": { "version": "2.1.2", @@ -3591,8 +3577,7 @@ "strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", - "dev": true + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=" }, "strip-json-comments": { "version": "3.1.1", @@ -3648,7 +3633,6 @@ "version": "3.12.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.12.0.tgz", "integrity": "sha512-e5adrnOYT6zqVnWqZu7i/BQ3BnhzvGbjEjejFXO20lKIKpwTaupkCPgEfv4GZK1IBciJUEhYs3J3p75FdaTFVg==", - "dev": true, "requires": { "@types/json5": "^0.0.29", "json5": "^1.0.1", diff --git a/package.json b/package.json index 31b8e24..9528044 100644 --- a/package.json +++ b/package.json @@ -1,42 +1,37 @@ { "name": "dist-gh-pages", - "version": "0.3.4", + "version": "0.4.0", "description": "Simple project for hosting static gh-pages (SPA further).", "keywords": [ "gh-pages", "free hosting", "static site", - "alias" + "alias", + "tsconfig-paths" ], "repository": { "type": "git", "url": "git://github.com/viT-1/dist-gh-pages.git" }, "scripts": { - "greet.node": "node -r esm -r module-alias/register ./distnode/main.js", + "greet.node": "node -r esm -r tsconfig-paths/register ./src/main", "lint": "eslint **/*.js", "copyfiles": "rm -rf dist && mkdir dist && cp -r ./src/** ./dist", - "copyfiles.node": "rm -rf distnode && mkdir distnode && cp -r ./src/** ./distnode", "replacestr": "node -r esm ./replace-in-file.js", - "replacestr.node": "node -r esm ./replace-in-file.js --greetnode", "build": "npm run copyfiles && npm run replacestr", - "build.node": "npm run copyfiles.node && npm run replacestr.node", "predeploy": "npm run build", "deploy": "gh-pages -d dist" }, "dependencies": { - "arg": "5.0.1", "esm": "3.2.25", "gh-pages": "3.2.3", - "module-alias": "2.2.2", + "tsconfig-paths": "3.12.0", "replace-in-file": "6.3.2" }, "devDependencies": { "eslint": "8.5.0", "eslint-plugin-import": "2.25.3", - "eslint-import-resolver-alias": "1.1.2" - }, - "_moduleAliases": { - "#common": "./distnode/common" + "eslint-import-resolver-node": "0.3.6", + "eslint-import-resolver-typescript": "2.5.0" } } \ No newline at end of file diff --git a/readme.md b/readme.md index 68e91df..bccf7e3 100644 --- a/readme.md +++ b/readme.md @@ -2,4 +2,7 @@ Simplest project for hosting static gh-pages (SPA further). Use `npm run deploy` for deploying dist folder to remote (no need to commit) repository on GitHub, then you can see [demo site](https://vit-1.github.io/dist-gh-pages/). -ESM aliases resolved by hands with [replace-in-file](https://github.com/adamreisnz/replace-in-file) node [script](https://github.com/viT-1/dist-gh-pages/blob/dce502b314fb81b4bf086af6b64fe983ff6cdde9/package.json#L21). \ No newline at end of file +ESM aliases resolved by hands with [replace-in-file](https://github.com/adamreisnz/replace-in-file) node [script](https://github.com/viT-1/dist-gh-pages/blob/dce502b314fb81b4bf086af6b64fe983ff6cdde9/package.json#L21). + +This project is not using TypeScript but using tsconfig.json > paths +to have single paths configuration for all (eslint, node, jest)! \ No newline at end of file diff --git a/replace-in-file.js b/replace-in-file.js index 0861d78..998e30b 100644 --- a/replace-in-file.js +++ b/replace-in-file.js @@ -1,12 +1,11 @@ -import arg from 'arg'; import replace from 'replace-in-file'; -import eslintConfig from './.eslintrc.json'; +import aliasConfig from './tsconfig.json'; import pjson from './package.json'; -const { devDependencies, name: ghPagesFolder } = pjson; +const { dependencies, name: ghPagesFolder } = pjson; const ghPagesModule = { name: 'gh-pages' }; -ghPagesModule.ver = devDependencies[ghPagesModule.name]; +ghPagesModule.ver = dependencies[ghPagesModule.name]; // replace info in html replace({ @@ -25,29 +24,22 @@ let jsStrFrom = new Array( let jsStrTo = ['', '$1$2$4.js$2', '$1$2$3$4$5/index.js$2']; -// --greetnode flag for node greeting option - no need to replace imports, -// should be resolved (but still isn't) by node native "imports" package.json key -const args = arg({ '--greetnode': Boolean }); - -// For Node alias resolving without tsc paths transpiling we forced to use module-aliases package, -// because native "imports" aren't working correctly yet: https://github.com/ilearnio/module-alias/issues/113 -if (!args['--greetnode']) { - // use eslint configuration for aliases - const eslintAliasMap = eslintConfig.settings['import/resolver'].alias.map; - eslintAliasMap.forEach(item => { - jsStrFrom.push(item[0]); - jsStrTo.push( - // bad code, inner knowledge, root is .io not project! - item[1].replace( - './src/', - `/${ghPagesFolder}/`, - )); - }); -} +// TODO: instead regex replacing alias map (bad replace '/*'), use tsconfig-paths createMatchPath +// use eslint configuration for aliases +const aliasMap = aliasConfig.compilerOptions.paths; +Object.keys(aliasMap).forEach(key => { + jsStrFrom.push(key.replace('/*', '')); + jsStrTo.push( + // bad code, inner knowledge, wwwroot is viT-1.io not this project root! + aliasMap[key][0].replace('/*', '').replace( + './src/', + `/${ghPagesFolder}/`, + )); +}); // replace imports in esm replace({ - files: args['--greetnode'] ? './distnode/**/*.js' : './dist/**/*.js', + files: './dist/**/*.js', from: jsStrFrom, to: jsStrTo, }); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..9af4a67 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "#common/*": ["./src/common/*"] + } + } +} \ No newline at end of file