From 95608c336e86b1b5fc3033aca521e1a65ba87b76 Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Wed, 1 Mar 2023 12:01:52 +0200 Subject: [PATCH] type module --- bin/package.json | 3 +++ index.js => index.cjs | 14 +++----------- index.mjs | 33 +++++++++++++++++++++++++++++++++ lib/package.json | 3 +++ package.json | 5 +++-- tests/package.json | 3 +++ 6 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 bin/package.json rename index.js => index.cjs (77%) create mode 100644 index.mjs create mode 100644 lib/package.json create mode 100644 tests/package.json diff --git a/bin/package.json b/bin/package.json new file mode 100644 index 0000000..3dbc1ca --- /dev/null +++ b/bin/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/index.js b/index.cjs similarity index 77% rename from index.js rename to index.cjs index 066b65f..44fa75d 100644 --- a/index.js +++ b/index.cjs @@ -16,7 +16,7 @@ * `require('')` is called. * * For this to work, it must be linked from `package.json` as - * `"main": "./index.js",`, which is, BTW, the default behaviour. + * `"exports": { "request": "./index.cjs" }`. * * To import classes from this module into Node.js applications, use: * @@ -25,10 +25,7 @@ * ``` */ -// ES6: `import { Main } from './lib/main.js' -import mainCsj from './lib/main.js' - -export const { Main } = mainCsj +const { Main } = require('./lib/main.js') // ---------------------------------------------------------------------------- // Node.js specific export definitions. @@ -36,11 +33,6 @@ export const { Main } = mainCsj // By default, `module.exports = {}`. // The Main class is added as a property with the same name to this object. -// module.exports.Main = Main - -// In ES6, it would be: -// export class Main { ... } -// ... -// import { Main } from 'module.js' +module.exports.Main = Main // ---------------------------------------------------------------------------- diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a6dbe94 --- /dev/null +++ b/index.mjs @@ -0,0 +1,33 @@ +/* + * This file is part of the xPack project (http://xpack.github.io). + * Copyright (c) 2017 Liviu Ionescu. All rights reserved. + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose is hereby granted, under the terms of the MIT license. + * + * If a copy of the license was not distributed with this file, it can + * be obtained from https://opensource.org/licenses/MIT/. + */ + +'use strict' + +/** + * This is the module entry point, the file that is processed when + * `import('')` is used. + * + * For this to work, it must be linked from `package.json` as + * `"exports": { "import": "./index.mjs" }`. + * + * To import classes from this module into Node.js applications, use: + * + * ```javascript + * import { Main } from '' + * ``` + */ + +// ES6: `import { Main } from './lib/main.js' +import mainCsj from './lib/main.js' + +export const { Main } = mainCsj + +// ---------------------------------------------------------------------------- diff --git a/lib/package.json b/lib/package.json new file mode 100644 index 0000000..3dbc1ca --- /dev/null +++ b/lib/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/package.json b/package.json index f3bf7c8..4ce31ad 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "xpm", "version": "0.15.0-pre", - "type": "module", "description": "The xPack project manager command line tool", + "type": "module", "exports": { - "import": "./index.js" + "request": "./index.cjs", + "import": "./index.mjs" }, "directories": { "bin": "./bin", diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 0000000..3dbc1ca --- /dev/null +++ b/tests/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +}