-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.js
44 lines (39 loc) · 1.42 KB
/
rollup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
require( `./index.js` );
const { deBypass, getConfig, isBypass, isExportable, isRoute, isValue } = require( `./lib/loader-utils` );
const { dirname } = require( `path` );
const generateModule = require( `./lib/generateModule` );
const UID = require( `./lib/UID` );
const marker = `\0~wires~${ UID }:`;
const getDirectory = path => ( path ? dirname( path ) : process.cwd() );
module.exports = () => ( {
load( id ) {
if ( id.startsWith( marker ) ) {
const [ directory, expression ] = JSON.parse( id.slice( marker.length ) );
return generateModule( getConfig( directory ).get( expression, false, true ) );
}
if ( isExportable( id ) ) {
return generateModule( id );
}
return null;
},
"name": `wires`,
resolveId( source, importer, options ) {
if ( isBypass( source ) ) {
return this.resolve( deBypass( source ), importer, {
...options,
"skipSelf": true,
} );
}
if ( isRoute( source ) ) {
return this.resolve( getConfig( getDirectory( importer ) ).get( source, true ).getValue(), importer, {
...options,
"skipSelf": true,
} );
}
if ( isValue( source ) ) {
return `${ marker }${ JSON.stringify( [ getDirectory( importer ), source ] ) }`;
}
return null;
},
} );