diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 95% rename from .eslintrc.js rename to .eslintrc.cjs index 07c0880..d6d6c07 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -7,7 +7,7 @@ module.exports = { 'plugin:react/recommended', ], parserOptions: { - ecmaVersion: 2018, + ecmaVersion: 20, sourceType: 'module', ecmaFeatures: { jsx: true, diff --git a/jest.config.js b/jest.config.cjs similarity index 100% rename from jest.config.js rename to jest.config.cjs diff --git a/package.json b/package.json index 3a77ef0..ff9f57e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,13 @@ { "name": "@adminjs/import-export", "version": "2.0.2", - "main": "lib/index.js", - "types": "types/index.d.ts", + "type": "module", + "exports": { + ".": { + "import": "./build/index.js", + "types": "./types/index.d.ts" + } + }, "private": false, "repository": "git@github.com:SoftwareBrothers/adminjs-import-export.git", "license": "SEE LICENSE IN LICENSE", @@ -52,7 +57,7 @@ "semantic-release": "^17.2.2", "ts-jest": "^26.4.3", "ts-node": "^9.0.0", - "typescript": "^4.0.5" + "typescript": "^4.9.5" }, "dependencies": { "@adminjs/mongoose": "^2.0.0", diff --git a/src/components/ExportComponent.tsx b/src/components/ExportComponent.tsx index 0c77577..7fbd50c 100644 --- a/src/components/ExportComponent.tsx +++ b/src/components/ExportComponent.tsx @@ -2,7 +2,7 @@ import React, { FC, useState } from 'react'; import { ActionProps, ApiClient, useNotice } from 'adminjs'; import { Box, Button, Loader, Text } from '@adminjs/design-system'; import { saveAs } from 'file-saver'; -import { Exporters, ExporterType } from '../exporter.type'; +import { Exporters, ExporterType } from '../exporter.type.js'; import format from 'date-fns/format'; export const mimeTypes: Record = { diff --git a/src/components/bundleComponents.ts b/src/components/bundleComponents.ts index 663819d..b420086 100644 --- a/src/components/bundleComponents.ts +++ b/src/components/bundleComponents.ts @@ -5,10 +5,10 @@ export const bundleComponents = (): { IMPORT_COMPONENT: string; } => { const EXPORT_COMPONENT = AdminJS.bundle( - '../../src/components/ExportComponent' + '../../src/components/ExportComponent.js' ); const IMPORT_COMPONENT = AdminJS.bundle( - '../../src/components/ImportComponent' + '../../src/components/ImportComponent.js' ); return { EXPORT_COMPONENT, IMPORT_COMPONENT }; diff --git a/src/export.handler.ts b/src/export.handler.ts index 6dd42fa..9b413a0 100644 --- a/src/export.handler.ts +++ b/src/export.handler.ts @@ -1,5 +1,5 @@ -import { Parsers } from './parsers'; -import { getRecords } from './utils'; +import { Parsers } from './parsers.js'; +import { getRecords } from './utils.js'; import { ActionHandler, ActionResponse } from 'adminjs'; export const exportHandler: ActionHandler = async ( diff --git a/src/import.handler.ts b/src/import.handler.ts index d8aec4d..80d411a 100644 --- a/src/import.handler.ts +++ b/src/import.handler.ts @@ -1,7 +1,7 @@ import { ActionHandler, ActionResponse } from 'adminjs'; import fs from 'fs'; import util from 'util'; -import { getFileFromRequest, getImporterByFileName } from './utils'; +import { getFileFromRequest, getImporterByFileName } from './utils.js'; const readFile = util.promisify(fs.readFile); diff --git a/src/importExportFeature.ts b/src/importExportFeature.ts index 0303148..0d3d9ef 100644 --- a/src/importExportFeature.ts +++ b/src/importExportFeature.ts @@ -1,8 +1,8 @@ import { buildFeature, FeatureType } from 'adminjs'; -import { bundleComponents } from './components/bundleComponents'; -import { postActionHandler } from './utils'; -import { exportHandler } from './export.handler'; -import { importHandler } from './import.handler'; +import { bundleComponents } from './components/bundleComponents.js'; +import { postActionHandler } from './utils.js'; +import { exportHandler } from './export.handler.js'; +import { importHandler } from './import.handler.js'; const { EXPORT_COMPONENT, IMPORT_COMPONENT } = bundleComponents(); diff --git a/src/index.ts b/src/index.ts index 9744558..4aba637 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,8 @@ * @section modules */ -import importExportFeature from './importExportFeature'; +import importExportFeature from './importExportFeature.js'; -export * from './components/bundleComponents'; +export * from './components/bundleComponents.js'; export default importExportFeature; diff --git a/src/modules/csv/csv.importer.ts b/src/modules/csv/csv.importer.ts index 5254a32..a35291e 100644 --- a/src/modules/csv/csv.importer.ts +++ b/src/modules/csv/csv.importer.ts @@ -1,6 +1,6 @@ import csv from 'csvtojson'; -import { Importer } from '../../parsers'; -import { saveRecords } from '../../utils'; +import { Importer } from '../../parsers.js'; +import { saveRecords } from '../../utils.js'; export const csvImporter: Importer = async (csvString, resource) => { const records = await csv().fromString(csvString); diff --git a/src/modules/json/json.importer.ts b/src/modules/json/json.importer.ts index 85d44aa..8df2466 100644 --- a/src/modules/json/json.importer.ts +++ b/src/modules/json/json.importer.ts @@ -1,5 +1,5 @@ -import { Importer } from '../../parsers'; -import { saveRecords } from '../../utils'; +import { Importer } from '../../parsers.js'; +import { saveRecords } from '../../utils.js'; export const jsonImporter: Importer = async (jsonString, resource) => { const records = JSON.parse(jsonString); diff --git a/src/modules/xml/xml.importer.ts b/src/modules/xml/xml.importer.ts index 1a8a278..e6a453c 100644 --- a/src/modules/xml/xml.importer.ts +++ b/src/modules/xml/xml.importer.ts @@ -1,6 +1,6 @@ -import { Importer } from '../../parsers'; +import { Importer } from '../../parsers.js'; import xml2js from 'xml2js'; -import { saveRecords } from '../../utils'; +import { saveRecords } from '../../utils.js'; export const xmlImporter: Importer = async (xmlString, resource) => { const parser = new xml2js.Parser({ explicitArray: false }); diff --git a/src/parsers.ts b/src/parsers.ts index 0de7dda..77642a1 100644 --- a/src/parsers.ts +++ b/src/parsers.ts @@ -1,11 +1,11 @@ import { BaseRecord, BaseResource } from 'adminjs'; -import { ExporterType } from './exporter.type'; -import { jsonExporter } from './modules/json/json.exporter'; -import { jsonImporter } from './modules/json/json.importer'; -import { csvExporter } from './modules/csv/csv.exporter'; -import { xmlExporter } from './modules/xml/xml.exporter'; -import { csvImporter } from './modules/csv/csv.importer'; -import { xmlImporter } from './modules/xml/xml.importer'; +import { ExporterType } from './exporter.type.js'; +import { jsonExporter } from './modules/json/json.exporter.js'; +import { jsonImporter } from './modules/json/json.importer.js'; +import { csvExporter } from './modules/csv/csv.exporter.js'; +import { xmlExporter } from './modules/xml/xml.exporter.js'; +import { csvImporter } from './modules/csv/csv.importer.js'; +import { xmlImporter } from './modules/xml/xml.importer.js'; export type Exporter = (records: BaseRecord[]) => string; diff --git a/src/utils.ts b/src/utils.ts index 84fd436..d4a65dd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -8,9 +8,9 @@ import { Filter, ValidationError, } from 'adminjs'; -import { csvImporter } from './modules/csv/csv.importer'; -import { jsonImporter } from './modules/json/json.importer'; -import { xmlImporter } from './modules/xml/xml.importer'; +import { csvImporter } from './modules/csv/csv.importer.js'; +import { jsonImporter } from './modules/json/json.importer.js'; +import { xmlImporter } from './modules/xml/xml.importer.js'; import { Importer } from './parsers'; export const saveRecords = async ( diff --git a/test/export-csv.test.ts b/test/export-csv.test.ts index 9b3f645..c0e8485 100644 --- a/test/export-csv.test.ts +++ b/test/export-csv.test.ts @@ -1,5 +1,5 @@ import AdminJS from 'adminjs'; -import importExportFeature from '../src'; +import importExportFeature from '../src/index.js'; import mongoose from 'mongoose'; import MongooseAdapter from '@adminjs/mongoose'; global.window = {} as any; @@ -27,7 +27,7 @@ class API extends ApiClient { } describe('CSV Export', () => { - it.skip('should assert true is ok', async function () { + it.skip('should assert true is ok', async function() { const adminJs = new AdminJS({ resources: [ { diff --git a/yarn.lock b/yarn.lock index 36956f9..41546ca 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11117,10 +11117,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" - integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== +typescript@^4.9.5: + version "4.9.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" + integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== uglify-js@^3.1.4: version "3.11.4"