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" +}