From b36d563267899fdaa0e406358b54453ca08180af Mon Sep 17 00:00:00 2001 From: Nathan Chase Date: Mon, 25 Jul 2022 16:01:53 -0400 Subject: [PATCH] WIP --- package.json | 20 +++---- playground/app.vue | 1 + pnpm-lock.yaml | 128 ++++++++++++++++++++++++++---------------- src/module.ts | 8 ++- src/runtime/plugin.ts | 14 +++-- tsconfig.json | 4 +- 6 files changed, 105 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index 1dc933b..9fa9354 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,23 @@ { "name": "@nathanchase/nuxt-dayjs-module", - "version": "1.0.3", + "version": "1.0.5", + "private": false, "description": "This is a Nuxt 3 compatible module built with the official Nuxt 3 (module-builder)(https://github.com/nuxt/module-builder) for (dayjs)(https://github.com/iamkun/dayjs/).", - "repository": { - "type": "git", - "url": "git+https://github.com/nathanchase/dayjs.git" - }, "keywords": [ "dayjs", "nuxt", "nuxt3" ], - "author": "Nathan Chase", + "homepage": "https://github.com/nathanchase/dayjs#readme", "bugs": { "url": "https://github.com/nathanchase/dayjs/issues" }, - "homepage": "https://github.com/nathanchase/dayjs#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/nathanchase/dayjs.git" + }, "license": "MIT", + "author": "Nathan Chase", "type": "module", "exports": { ".": { @@ -29,12 +30,11 @@ "files": [ "dist" ], - "private": false, "scripts": { - "prepack": "nuxt-module-build", "dev": "nuxi dev playground", "dev:build": "nuxi build playground", - "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground" + "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground", + "prepack": "nuxt-module-build" }, "dependencies": { "@nuxt/kit": "^3.0.0-rc.6", diff --git a/playground/app.vue b/playground/app.vue index f5d4f40..789f7cb 100644 --- a/playground/app.vue +++ b/playground/app.vue @@ -4,6 +4,7 @@

Unformatted: {{ new Date() }}

Formatted with dayjs (template): {{ $dayjs(new Date()).format('DD/MM/YYYY') }}

Formatted with dayjs (computed): {{ prettyDate }}

+

Formatted with dayjs (RelativeTime): {{ $dayjs(new Date()).fromNow() }}

diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ede00ed..2314c8b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -648,6 +648,7 @@ packages: - sass - stylus - supports-color + - terser - webpack dev: true @@ -656,26 +657,26 @@ packages: peerDependencies: eslint: ^8.14.0 dependencies: - '@nuxtjs/eslint-config': 10.0.0_w3h2x6a7zgcj3scdfl3yk2yqgq - '@typescript-eslint/eslint-plugin': 5.30.7_xconv27bia2733zao6ipggqv2i - '@typescript-eslint/parser': 5.30.7_eslint@8.20.0 + '@nuxtjs/eslint-config': 10.0.0_xghit6br4uxxcb3wedzz63s5dy + '@typescript-eslint/eslint-plugin': 5.31.0_ficupzxy3q6nk56ibvavehtzue + '@typescript-eslint/parser': 5.31.0_eslint@8.20.0 eslint: 8.20.0 eslint-import-resolver-typescript: 2.7.1_afl3vkhn63baibzal45igheroq - eslint-plugin-import: 2.26.0_w3h2x6a7zgcj3scdfl3yk2yqgq + eslint-plugin-import: 2.26.0_xghit6br4uxxcb3wedzz63s5dy transitivePeerDependencies: - eslint-import-resolver-webpack - supports-color - typescript dev: true - /@nuxtjs/eslint-config/10.0.0_w3h2x6a7zgcj3scdfl3yk2yqgq: + /@nuxtjs/eslint-config/10.0.0_xghit6br4uxxcb3wedzz63s5dy: resolution: {integrity: sha512-5umb4Nyd/D9azWyFPGe3ru0E5v8SSVzgtZeJwTaCpqjsQDrr51P7QPtBTVdJXIbhdY1lws67x9Emkb7oKwh4zw==} peerDependencies: eslint: ^8.14.0 dependencies: eslint: 8.20.0 eslint-config-standard: 17.0.0_aabay5xq26dqolh67bnodxi5n4 - eslint-plugin-import: 2.26.0_w3h2x6a7zgcj3scdfl3yk2yqgq + eslint-plugin-import: 2.26.0_xghit6br4uxxcb3wedzz63s5dy eslint-plugin-n: 15.2.4_eslint@8.20.0 eslint-plugin-node: 11.1.0_eslint@8.20.0 eslint-plugin-promise: 6.0.0_eslint@8.20.0 @@ -864,8 +865,8 @@ packages: resolution: {integrity: sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw==} dev: true - /@typescript-eslint/eslint-plugin/5.30.7_xconv27bia2733zao6ipggqv2i: - resolution: {integrity: sha512-l4L6Do+tfeM2OK0GJsU7TUcM/1oN/N25xHm3Jb4z3OiDU4Lj8dIuxX9LpVMS9riSXQs42D1ieX7b85/r16H9Fw==} + /@typescript-eslint/eslint-plugin/5.31.0_ficupzxy3q6nk56ibvavehtzue: + resolution: {integrity: sha512-VKW4JPHzG5yhYQrQ1AzXgVgX8ZAJEvCz0QI6mLRX4tf7rnFfh5D8SKm0Pq6w5PyNfAWJk6sv313+nEt3ohWMBQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: '@typescript-eslint/parser': ^5.0.0 @@ -875,10 +876,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.30.7_eslint@8.20.0 - '@typescript-eslint/scope-manager': 5.30.7 - '@typescript-eslint/type-utils': 5.30.7_eslint@8.20.0 - '@typescript-eslint/utils': 5.30.7_eslint@8.20.0 + '@typescript-eslint/parser': 5.31.0_eslint@8.20.0 + '@typescript-eslint/scope-manager': 5.31.0 + '@typescript-eslint/type-utils': 5.31.0_eslint@8.20.0 + '@typescript-eslint/utils': 5.31.0_eslint@8.20.0 debug: 4.3.4 eslint: 8.20.0 functional-red-black-tree: 1.0.1 @@ -890,8 +891,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.30.7_eslint@8.20.0: - resolution: {integrity: sha512-Rg5xwznHWWSy7v2o0cdho6n+xLhK2gntImp0rJroVVFkcYFYQ8C8UJTSuTw/3CnExBmPjycjmUJkxVmjXsld6A==} + /@typescript-eslint/parser/5.31.0_eslint@8.20.0: + resolution: {integrity: sha512-UStjQiZ9OFTFReTrN+iGrC6O/ko9LVDhreEK5S3edmXgR396JGq7CoX2TWIptqt/ESzU2iRKXAHfSF2WJFcWHw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 @@ -900,25 +901,25 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 5.30.7 - '@typescript-eslint/types': 5.30.7 - '@typescript-eslint/typescript-estree': 5.30.7 + '@typescript-eslint/scope-manager': 5.31.0 + '@typescript-eslint/types': 5.31.0 + '@typescript-eslint/typescript-estree': 5.31.0 debug: 4.3.4 eslint: 8.20.0 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/scope-manager/5.30.7: - resolution: {integrity: sha512-7BM1bwvdF1UUvt+b9smhqdc/eniOnCKxQT/kj3oXtj3LqnTWCAM0qHRHfyzCzhEfWX0zrW7KqXXeE4DlchZBKw==} + /@typescript-eslint/scope-manager/5.31.0: + resolution: {integrity: sha512-8jfEzBYDBG88rcXFxajdVavGxb5/XKXyvWgvD8Qix3EEJLCFIdVloJw+r9ww0wbyNLOTYyBsR+4ALNGdlalLLg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.30.7 - '@typescript-eslint/visitor-keys': 5.30.7 + '@typescript-eslint/types': 5.31.0 + '@typescript-eslint/visitor-keys': 5.31.0 dev: true - /@typescript-eslint/type-utils/5.30.7_eslint@8.20.0: - resolution: {integrity: sha512-nD5qAE2aJX/YLyKMvOU5jvJyku4QN5XBVsoTynFrjQZaDgDV6i7QHFiYCx10wvn7hFvfuqIRNBtsgaLe0DbWhw==} + /@typescript-eslint/type-utils/5.31.0_eslint@8.20.0: + resolution: {integrity: sha512-7ZYqFbvEvYXFn9ax02GsPcEOmuWNg+14HIf4q+oUuLnMbpJ6eHAivCg7tZMVwzrIuzX3QCeAOqKoyMZCv5xe+w==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: '*' @@ -927,7 +928,7 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/utils': 5.30.7_eslint@8.20.0 + '@typescript-eslint/utils': 5.31.0_eslint@8.20.0 debug: 4.3.4 eslint: 8.20.0 tsutils: 3.21.0 @@ -935,13 +936,13 @@ packages: - supports-color dev: true - /@typescript-eslint/types/5.30.7: - resolution: {integrity: sha512-ocVkETUs82+U+HowkovV6uxf1AnVRKCmDRNUBUUo46/5SQv1owC/EBFkiu4MOHeZqhKz2ktZ3kvJJ1uFqQ8QPg==} + /@typescript-eslint/types/5.31.0: + resolution: {integrity: sha512-/f/rMaEseux+I4wmR6mfpM2wvtNZb1p9hAV77hWfuKc3pmaANp5dLAZSiE3/8oXTYTt3uV9KW5yZKJsMievp6g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.30.7: - resolution: {integrity: sha512-tNslqXI1ZdmXXrHER83TJ8OTYl4epUzJC0aj2i4DMDT4iU+UqLT3EJeGQvJ17BMbm31x5scSwo3hPM0nqQ1AEA==} + /@typescript-eslint/typescript-estree/5.31.0: + resolution: {integrity: sha512-3S625TMcARX71wBc2qubHaoUwMEn+l9TCsaIzYI/ET31Xm2c9YQ+zhGgpydjorwQO9pLfR/6peTzS/0G3J/hDw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: typescript: '*' @@ -949,8 +950,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 5.30.7 - '@typescript-eslint/visitor-keys': 5.30.7 + '@typescript-eslint/types': 5.31.0 + '@typescript-eslint/visitor-keys': 5.31.0 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 @@ -960,16 +961,16 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.30.7_eslint@8.20.0: - resolution: {integrity: sha512-Z3pHdbFw+ftZiGUnm1GZhkJgVqsDL5CYW2yj+TB2mfXDFOMqtbzQi2dNJIyPqPbx9mv2kUxS1gU+r2gKlKi1rQ==} + /@typescript-eslint/utils/5.31.0_eslint@8.20.0: + resolution: {integrity: sha512-kcVPdQS6VIpVTQ7QnGNKMFtdJdvnStkqS5LeALr4rcwx11G6OWb2HB17NMPnlRHvaZP38hL9iK8DdE9Fne7NYg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: '@types/json-schema': 7.0.11 - '@typescript-eslint/scope-manager': 5.30.7 - '@typescript-eslint/types': 5.30.7 - '@typescript-eslint/typescript-estree': 5.30.7 + '@typescript-eslint/scope-manager': 5.31.0 + '@typescript-eslint/types': 5.31.0 + '@typescript-eslint/typescript-estree': 5.31.0 eslint: 8.20.0 eslint-scope: 5.1.1 eslint-utils: 3.0.0_eslint@8.20.0 @@ -978,11 +979,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys/5.30.7: - resolution: {integrity: sha512-KrRXf8nnjvcpxDFOKej4xkD7657+PClJs5cJVSG7NNoCNnjEdc46juNAQt7AyuWctuCgs6mVRc1xGctEqrjxWw==} + /@typescript-eslint/visitor-keys/5.31.0: + resolution: {integrity: sha512-ZK0jVxSjS4gnPirpVjXHz7mgdOsZUHzNYSfTw2yPa3agfbt9YfqaBiBZFSSxeBWnpWkzCxTfUpnzA3Vily/CSg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.30.7 + '@typescript-eslint/types': 5.31.0 eslint-visitor-keys: 3.3.0 dev: true @@ -2287,7 +2288,7 @@ packages: eslint-plugin-promise: ^6.0.0 dependencies: eslint: 8.20.0 - eslint-plugin-import: 2.26.0_w3h2x6a7zgcj3scdfl3yk2yqgq + eslint-plugin-import: 2.26.0_xghit6br4uxxcb3wedzz63s5dy eslint-plugin-n: 15.2.4_eslint@8.20.0 eslint-plugin-promise: 6.0.0_eslint@8.20.0 dev: true @@ -2310,7 +2311,7 @@ packages: dependencies: debug: 4.3.4 eslint: 8.20.0 - eslint-plugin-import: 2.26.0_w3h2x6a7zgcj3scdfl3yk2yqgq + eslint-plugin-import: 2.26.0_xghit6br4uxxcb3wedzz63s5dy glob: 7.2.3 is-glob: 4.0.3 resolve: 1.22.1 @@ -2319,7 +2320,7 @@ packages: - supports-color dev: true - /eslint-module-utils/2.7.3_ggupe3rfxc6u74is6c4nrru3k4: + /eslint-module-utils/2.7.3_tl7yzo5qhybg5tc7vdth5gpmla: resolution: {integrity: sha512-088JEC7O3lDZM9xGe0RerkOMd0EjFl+Yvd1jPWIkMT5u3H9+HC34mWWPnqPrN13gieT9pBOO+Qt07Nb/6TresQ==} engines: {node: '>=4'} peerDependencies: @@ -2337,7 +2338,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 5.30.7_eslint@8.20.0 + '@typescript-eslint/parser': 5.31.0_eslint@8.20.0 debug: 3.2.7 eslint-import-resolver-node: 0.3.6 eslint-import-resolver-typescript: 2.7.1_afl3vkhn63baibzal45igheroq @@ -2368,7 +2369,7 @@ packages: regexpp: 3.2.0 dev: true - /eslint-plugin-import/2.26.0_w3h2x6a7zgcj3scdfl3yk2yqgq: + /eslint-plugin-import/2.26.0_xghit6br4uxxcb3wedzz63s5dy: resolution: {integrity: sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==} engines: {node: '>=4'} peerDependencies: @@ -2378,14 +2379,14 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 5.30.7_eslint@8.20.0 + '@typescript-eslint/parser': 5.31.0_eslint@8.20.0 array-includes: 3.1.5 array.prototype.flat: 1.3.0 debug: 2.6.9 doctrine: 2.1.0 eslint: 8.20.0 eslint-import-resolver-node: 0.3.6 - eslint-module-utils: 2.7.3_ggupe3rfxc6u74is6c4nrru3k4 + eslint-module-utils: 2.7.3_tl7yzo5qhybg5tc7vdth5gpmla has: 1.0.3 is-core-module: 2.9.0 is-glob: 4.0.3 @@ -2910,7 +2911,7 @@ packages: resolution: {integrity: sha512-YUvVDg/vX3d0syBsk/CKUTib0srcQME0JyHkL5BaYdwLsiCslPWmDSi8PUMo9pXYjrryMcmsCoCgsTpSCJEQaA==} dependencies: is-ssh: 1.4.0 - parse-url: 6.0.3 + parse-url: 6.0.5 dev: true /git-url-parse/11.6.0: @@ -4023,6 +4024,7 @@ packages: - sass - stylus - supports-color + - terser - utf-8-validate - vite - webpack @@ -4207,8 +4209,8 @@ packages: query-string: 6.14.1 dev: true - /parse-url/6.0.3: - resolution: {integrity: sha512-gxeYC5LVOWg1po3HjHF1JHyyI+kDp/ziEGWUv+smkonT//KRI8TM0zi+yj4e2EZWZ+WGiTPIG1WJSkWZE7isWg==} + /parse-url/6.0.5: + resolution: {integrity: sha512-e35AeLTSIlkw/5GFq70IN7po8fmDUjpDPY1rIK+VubRfsUvBonjQ+PBZG+vWMACnQSmNlvl524IucoDmcioMxA==} dependencies: is-ssh: 1.4.0 normalize-url: 6.1.0 @@ -5779,12 +5781,13 @@ packages: kolorist: 1.5.1 mlly: 0.5.5 pathe: 0.2.0 - vite: 2.9.14 + vite: 3.0.3 transitivePeerDependencies: - less - sass - stylus - supports-color + - terser dev: true /vite-plugin-checker/0.4.9_vite@2.9.14: @@ -5835,6 +5838,33 @@ packages: fsevents: 2.3.2 dev: true + /vite/3.0.3: + resolution: {integrity: sha512-sDIpIcl3mv1NUaSzZwiXGEy1ZoWwwC2vkxUHY6yiDacR6zf//ZFuBJrozO62gedpE43pmxnLATNR5IYUdAEkMQ==} + engines: {node: ^14.18.0 || >=16.0.0} + hasBin: true + peerDependencies: + less: '*' + sass: '*' + stylus: '*' + terser: ^5.4.0 + peerDependenciesMeta: + less: + optional: true + sass: + optional: true + stylus: + optional: true + terser: + optional: true + dependencies: + esbuild: 0.14.50 + postcss: 8.4.14 + resolve: 1.22.1 + rollup: 2.77.0 + optionalDependencies: + fsevents: 2.3.2 + dev: true + /vscode-jsonrpc/6.0.0: resolution: {integrity: sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==} engines: {node: '>=8.0.0 || >=10.0.0'} diff --git a/src/module.ts b/src/module.ts index d580dde..6ff40d9 100644 --- a/src/module.ts +++ b/src/module.ts @@ -14,14 +14,16 @@ export default defineNuxtModule({ nuxt: '^3.0.0' } }, + defaults: { addPlugin: true }, - setup (options, nuxt) { + + async setup (options, nuxt) { if (options.addPlugin) { const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url)) - nuxt.options.build.transpile.push(runtimeDir) - addPlugin(resolve(runtimeDir, 'plugin')) + await nuxt.options.build.transpile.push(runtimeDir) + await addPlugin(resolve(runtimeDir, 'plugin')) } } }) diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index 3168fd1..733a66b 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -1,10 +1,16 @@ + import dayjs from 'dayjs' import duration from 'dayjs/plugin/duration' import relativeTime from 'dayjs/plugin/relativeTime' -// import advancedFormat from 'dayjs/plugin/advancedFormat' -// import weekday from 'dayjs/plugin/weekday' +import advancedFormat from 'dayjs/plugin/advancedFormat' +import weekday from 'dayjs/plugin/weekday' import { defineNuxtPlugin } from '#app' +dayjs.extend(duration) +dayjs.extend(relativeTime) +dayjs.extend(advancedFormat) +dayjs.extend(weekday) + declare module '#app' { interface NuxtApp { $dayjs: dayjs.Dayjs @@ -18,9 +24,5 @@ declare module '@vue/runtime-core' { } export default defineNuxtPlugin((nuxtApp) => { - dayjs.extend(duration) - dayjs.extend(relativeTime) - // dayjs.extend(advancedFormat) - // dayjs.extend(weekday) nuxtApp.provide('dayjs', dayjs) }) diff --git a/tsconfig.json b/tsconfig.json index 648c4df..a0d2d00 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,8 @@ "dayjs", "dayjs/plugin/duration", "dayjs/plugin/relativeTime", - // "dayjs/plugin/advancedFormat", - // "dayjs/plugin/weekday" + "dayjs/plugin/advancedFormat", + "dayjs/plugin/weekday" ] } }