Skip to content

Commit

Permalink
chore: change to ECMAScript modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarosław Wasiak committed Mar 7, 2023
1 parent 8c3778c commit 83e607a
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
'plugin:react/recommended',
],
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 20,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
Expand Down
File renamed without changes.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]:SoftwareBrothers/adminjs-import-export.git",
"license": "SEE LICENSE IN LICENSE",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExportComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExporterType, string> = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/bundleComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
4 changes: 2 additions & 2 deletions src/export.handler.ts
Original file line number Diff line number Diff line change
@@ -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<ActionResponse> = async (
Expand Down
2 changes: 1 addition & 1 deletion src/import.handler.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
8 changes: 4 additions & 4 deletions src/importExportFeature.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions src/modules/csv/csv.importer.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/json/json.importer.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/xml/xml.importer.ts
Original file line number Diff line number Diff line change
@@ -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 });
Expand Down
14 changes: 7 additions & 7 deletions src/parsers.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions test/export-csv.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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: [
{
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 83e607a

Please sign in to comment.