Skip to content

Commit

Permalink
type module
Browse files Browse the repository at this point in the history
  • Loading branch information
ilg-ul committed Mar 1, 2023
1 parent 67fbb5e commit 95608c3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
3 changes: 3 additions & 0 deletions bin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
14 changes: 3 additions & 11 deletions index.js → index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* `require('<module>')` 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:
*
Expand All @@ -25,22 +25,14 @@
* ```
*/

// 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.

// 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

// ----------------------------------------------------------------------------
33 changes: 33 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -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('<module>')` 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 '<module>'
* ```
*/

// ES6: `import { Main } from './lib/main.js'
import mainCsj from './lib/main.js'

export const { Main } = mainCsj

// ----------------------------------------------------------------------------
3 changes: 3 additions & 0 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}

0 comments on commit 95608c3

Please sign in to comment.