Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

[WIP] BREAKING: interop, take 2 #92

Merged
merged 11 commits into from
Aug 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"rules": {
"indent": [ 2, "tab", { "SwitchCase": 1 } ],
"quotes": [ 2, "single" ],
"linebreak-style": [ 2, "unix" ],
"semi": [ 2, "always" ],
"space-after-keywords": [ 2, "always" ],
"space-before-blocks": [ 2, "always" ],
"space-before-function-paren": [ 2, "always" ],
"no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ],
"no-cond-assign": [ 0 ]
},
"env": {
"es6": true,
"browser": true,
"mocha": true,
"node": true
},
"extends": "eslint:recommended",
"ecmaFeatures": {
"modules": true
}
"rules": {
"indent": [ 2, "tab", { "SwitchCase": 1 } ],
"quotes": [ 2, "single", { "allowTemplateLiterals": true } ],
"linebreak-style": [ 2, "unix" ],
"semi": [ 2, "always" ],
"keyword-spacing": [ 2, { "before": true, "after": true } ],
"space-before-blocks": [ 2, "always" ],
"space-before-function-paren": [ 2, "always" ],
"no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ],
"no-cond-assign": [ 0 ]
},
"env": {
"es6": true,
"browser": true,
"mocha": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"rollup": "^0.33.0",
"rollup-plugin-buble": "^0.12.1",
"rollup-plugin-node-resolve": "^1.7.1",
"source-map": "^0.5.6"
"source-map": "^0.5.6",
"source-map-support": "^0.4.2"
},
"main": "dist/rollup-plugin-commonjs.cjs.js",
"jsnext:main": "dist/rollup-plugin-commonjs.es.js",
Expand Down
9 changes: 7 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ var external = Object.keys( require( './package.json' ).dependencies ).concat([

export default {
entry: 'src/index.js',
plugins: [ buble() ],
external: external
plugins: [
buble({
transforms: { dangerousForOf: true }
})
],
external: external,
sourceMap: true
};
39 changes: 39 additions & 0 deletions src/defaultResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as fs from 'fs';
import { dirname, resolve } from 'path';

function isFile ( file ) {
try {
const stats = fs.statSync( file );
return stats.isFile();
} catch ( err ) {
return false;
}
}

function addJsExtensionIfNecessary ( file ) {
if ( isFile( file ) ) return file;

file += '.js';
if ( isFile( file ) ) return file;

return null;
}

const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|\/])/;

function isAbsolute ( path ) {
return absolutePath.test( path );
}

export default function defaultResolver ( importee, importer ) {
// absolute paths are left untouched
if ( isAbsolute( importee ) ) return addJsExtensionIfNecessary( resolve( importee ) );

// if this is the entry point, resolve against cwd
if ( importer === undefined ) return addJsExtensionIfNecessary( resolve( process.cwd(), importee ) );

// external modules are skipped at this stage
if ( importee[0] !== '.' ) return null;

return addJsExtensionIfNecessary( resolve( dirname( importer ), importee ) );
}
15 changes: 15 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const HELPERS_ID = '\0commonjsHelpers';

export const HELPERS = `
export var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

export function unwrapExports (x) {
return x && x.__esModule ? x['default'] : x;
}

export function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}`;

export const PREFIX = '\0commonjs-proxy:';
export const EXTERNAL = '\0commonjs-external:';
Loading