{"_id":"babel-plugin-transform-cjs-dew","_rev":"131428","name":"babel-plugin-transform-cjs-dew","description":"Converts CommonJS modules into ES modules","dist-tags":{"latest":"1.0.2"},"maintainers":[{"name":"guybedford","email":"guybedford@gmail.com"}],"time":{"modified":"2021-06-03T11:11:26.000Z","created":"2019-04-23T23:06:19.643Z","1.0.2":"2019-07-25T04:35:29.287Z","1.0.1":"2019-07-25T03:30:01.373Z","1.0.0":"2019-04-23T23:06:19.643Z"},"users":{},"author":{"name":"Guy Bedford"},"repository":{"type":"git","url":"git+ssh://git@github.com/jspm/babel-plugin-transform-cjs-dew.git"},"versions":{"1.0.2":{"name":"babel-plugin-transform-cjs-dew","version":"1.0.2","description":"Converts CommonJS modules into ES modules","repository":{"type":"git","url":"git+ssh://git@github.com/jspm/babel-plugin-transform-cjs-dew.git"},"author":{"name":"Guy Bedford"},"license":"MIT","main":"transform-cjs-dew.js","devDependencies":{"@babel/core":"^7.0.0","mocha":"^3.4.2"},"scripts":{"test":"mocha"},"dependencies":{"@babel/parser":"^7.1.0"},"gitHead":"0ba464aa3f044975b8350fbfcfdb01c056d0a969","bugs":{"url":"https://github.com/jspm/babel-plugin-transform-cjs-dew/issues"},"homepage":"https://github.com/jspm/babel-plugin-transform-cjs-dew#readme","_id":"babel-plugin-transform-cjs-dew@1.0.2","_nodeVersion":"12.6.0","_npmVersion":"6.9.0","dist":{"shasum":"bed8d243a8319a39a2c57b0952134ee150a548b8","size":32761,"noattachment":false,"key":"/babel-plugin-transform-cjs-dew/-/babel-plugin-transform-cjs-dew-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-cjs-dew/download/babel-plugin-transform-cjs-dew-1.0.2.tgz"},"maintainers":[{"name":"guybedford","email":"guybedford@gmail.com"}],"_npmUser":{"name":"guybedford","email":"guybedford@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-cjs-dew_1.0.2_1564029329131_0.8265201477366695"},"_hasShrinkwrap":false,"publish_time":1564029329287,"_cnpm_publish_time":1564029329287},"1.0.1":{"name":"babel-plugin-transform-cjs-dew","version":"1.0.1","description":"Converts CommonJS modules into ES modules","repository":{"type":"git","url":"git+ssh://git@github.com/jspm/babel-plugin-transform-cjs-dew.git"},"author":{"name":"Guy Bedford"},"license":"MIT","main":"transform-cjs-dew.js","devDependencies":{"@babel/core":"^7.0.0","mocha":"^3.4.2"},"scripts":{"test":"mocha"},"dependencies":{"@babel/parser":"^7.1.0"},"gitHead":"b3c06ff68387eefbf29b51a2be6e403b51ba9f41","bugs":{"url":"https://github.com/jspm/babel-plugin-transform-cjs-dew/issues"},"homepage":"https://github.com/jspm/babel-plugin-transform-cjs-dew#readme","_id":"babel-plugin-transform-cjs-dew@1.0.1","_nodeVersion":"12.6.0","_npmVersion":"6.9.0","dist":{"shasum":"bc4a77ac1af9224cf4e18e591a5da64524f8f04c","size":32780,"noattachment":false,"key":"/babel-plugin-transform-cjs-dew/-/babel-plugin-transform-cjs-dew-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-cjs-dew/download/babel-plugin-transform-cjs-dew-1.0.1.tgz"},"maintainers":[{"name":"guybedford","email":"guybedford@gmail.com"}],"_npmUser":{"name":"guybedford","email":"guybedford@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-cjs-dew_1.0.1_1564025401245_0.1599223183178533"},"_hasShrinkwrap":false,"publish_time":1564025401373,"_cnpm_publish_time":1564025401373},"1.0.0":{"name":"babel-plugin-transform-cjs-dew","version":"1.0.0","description":"Converts CommonJS modules into ES modules","repository":{"type":"git","url":"git+ssh://git@github.com/jspm/babel-plugin-transform-cjs-dew.git"},"author":{"name":"Guy Bedford"},"license":"MIT","main":"transform-cjs-dew.js","devDependencies":{"@babel/core":"^7.0.0","mocha":"^3.4.2"},"scripts":{"test":"mocha"},"dependencies":{"@babel/parser":"^7.1.0"},"gitHead":"4ab4d19fc77726ab40fddcdb40e5c1bff51fd9b1","bugs":{"url":"https://github.com/jspm/babel-plugin-transform-cjs-dew/issues"},"homepage":"https://github.com/jspm/babel-plugin-transform-cjs-dew#readme","_id":"babel-plugin-transform-cjs-dew@1.0.0","_nodeVersion":"11.14.0","_npmVersion":"6.7.0","dist":{"shasum":"d399486468bac2ed8a2d0da6f3dcde610e828edf","size":32497,"noattachment":false,"key":"/babel-plugin-transform-cjs-dew/-/babel-plugin-transform-cjs-dew-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-transform-cjs-dew/download/babel-plugin-transform-cjs-dew-1.0.0.tgz"},"maintainers":[{"name":"guybedford","email":"guybedford@gmail.com"}],"_npmUser":{"name":"guybedford","email":"guybedford@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/babel-plugin-transform-cjs-dew_1.0.0_1556060779506_0.3409357237005042"},"_hasShrinkwrap":false,"publish_time":1556060779643,"_cnpm_publish_time":1556060779643}},"readme":"# Babel CommonJS -> ES Deferred Execution Wrapper Format\r\n\r\nThis plugin implements a deferred execution wodule format that allows supporting CommonJS execution semantics through an ES modules protocol.\r\n\r\n_Modules converted in this way can only import from other modules converted to this format._\r\n\r\nThis project aims for accuracy and reliability transforming a tree of CommonJS modules into a spec-compliant tree of ES Modules.\r\n\r\n```js\r\nrequire('babel-core').transform('<source>', {\r\n  parserOpts: {\r\n    allowReturnOutsideFunction: true\r\n  },\r\n  plugins: [\r\n    ['transform-cjs-dew', {\r\n      filename: '\"custom-filename.js\"',\r\n      dirname: '\"/dirname\"',\r\n      define: {\r\n        'process.env.NODE_ENV': '\"development\"'\r\n      },\r\n      resolve (name, { wildcard?, optional?, browserResolve? }) {\r\n        if (name === 'process')\r\n          return 'process-path';\r\n        if (name === './x')\r\n          return './x.js';\r\n      },\r\n      // for wildcard requires, return a string or array or null to indicate unknown resolution\r\n      // '@empty' indicates an empty object resolution, where all named exports are undefined\r\n      // by default, a null resolve embeds a Node require through a import 'module' path\r\n      // browserOnly just inlines the module not found error directly\r\n      browserOnly: false,\r\n      // when a wildcard ends in *, permit automatic extension variations\r\n      // in the conditional expression output\r\n      wildcardExtensions: ['.js'],\r\n      // optional support for ESM dependencies with default export\r\n      esmDependencies (resolved) {\r\n        return resolved.endsWith('.mjs');\r\n      }\r\n    }]\r\n  ]\r\n});\r\n```\r\n\r\nOutput:\r\n\r\n```js\r\nimport { dew as _depDew } from './dep.dew.js';\r\nimport depB from './dep.mjs';\r\nvar exports = {};\r\nvar module = {\r\n  get exports () {\r\n    return exports;\r\n  }\r\n  set exports (_exports) {\r\n    exports = _exports;\r\n  }\r\n};\r\nexport function dew () {\r\n  if (executed)\r\n    return module.exports;\r\n  executed = true;\r\n  __dew__ = null;\r\n  module.exports = function () {};\r\n  exports.blah = 'hi';\r\n  var a = _depDew().y;\r\n  var b = depB;\r\n  return module.exports;\r\n}\r\n```\r\n\r\nTo import a CommonJS module tree converted via the above into an ES module, the following\r\n_execution wrapper_ is required:\r\n\r\nx.js\r\n```js\r\nimport { dew } from './x.dew.js';\r\nexport default dew();\r\n```\r\n\r\nAs well as execution wrapping, the following code transformations are handled:\r\n* Simple 'use strict' code conversion if not already strict.\r\n* Defines the `exports` and `module` variables in module scope.\r\n* Any use of `global` or `GLOBAL` defines global in the module scope.\r\n* Top-level `this` is replaced with an `exports` reference.\r\n* Top-level `return` is adjusted to always ensure a falsy return value.\r\n* Internal `this` references that are not direct calls, fallback to _global.\r\n* Implicit globals of the form `globalName = ...` are rescoped for a simple strict module conversion.\r\n* Use of `Buffer` and `process` is transformed into an import of `buffer` or `process`. This module name can be customized by the `map` configuration option.\r\n\r\nThe remaining strict conversion cases that don't convert are then just the edge cases of loose -> strict mode conversion:\r\n* Any use of `with` statements will throw\r\n* Multiple duplicate function parameters\r\n* Relying on dynamic arguments\r\n* Assigning to reserved names\r\n* Using eval to define variables\r\n* Expecting `this` being the global as the default context for function calls\r\n* `delete` statements of local variables are removed\r\n\r\nThe above should comprehensively cover the failure cases.\r\n\r\n## License\r\n\r\nMIT\r\n","_attachments":{},"homepage":"https://github.com/jspm/babel-plugin-transform-cjs-dew#readme","bugs":{"url":"https://github.com/jspm/babel-plugin-transform-cjs-dew/issues"},"license":"MIT"}