-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d11aa65
Showing
13 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file is for unifying the coding style for different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/testdata/ | ||
/node_modules/ | ||
/coverage/ | ||
/.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"extends": ["standard", "prettier", "prettier/standard"], | ||
"plugins": ["import", "mocha"], | ||
"env": { | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"prefer-template": "error", | ||
"mocha/no-exclusive-tests": "error", | ||
"mocha/no-nested-tests": "error", | ||
"mocha/no-identical-title": "error", | ||
"prefer-const": [ | ||
"error", | ||
{ | ||
"destructuring": "all", | ||
"ignoreReadBeforeAssign": false | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules/ | ||
/coverage/ | ||
/.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
save-exact = false | ||
package-lock = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/coverage/ | ||
|
||
# Don't fight npm i --save | ||
package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: node_js | ||
node_js: | ||
- 8 | ||
- 10 | ||
- 12 | ||
- 14 | ||
- node | ||
|
||
matrix: | ||
include: | ||
- name: Lint | ||
node_js: 14 | ||
script: npm run lint | ||
|
||
script: npm run test:ci | ||
after_success: '<coverage/lcov.info ./node_modules/coveralls/bin/coveralls.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Test suite", | ||
"program": "${workspaceFolder}/node_modules/.bin/_mocha", | ||
"args": ["--timeout", "9999999999"], | ||
"skipFiles": [ | ||
"<node_internals>/**" // Prevent stepping through async_hooks.js et al. | ||
], | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"console": "internalConsole", | ||
"outputCapture": "std" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Mocha current file", | ||
"cwd": "${workspaceRoot}", | ||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/mocha", | ||
"windows": { | ||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/mocha.cmd" | ||
}, | ||
"runtimeArgs": [ | ||
"--timeout", | ||
"999999", | ||
"--colors", | ||
"--recursive", | ||
"${file}" | ||
], | ||
"skipFiles": [ | ||
"<node_internals>/**" // Prevent stepping through async_hooks.js et al. | ||
], | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"console": "internalConsole", | ||
"outputCapture": "std" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const urlTools = require('urltools'); | ||
|
||
module.exports = async function bundleRollup(assetGraph, htmlAsset) { | ||
let rollup; | ||
try { | ||
rollup = require('rollup'); | ||
} catch (e) { | ||
throw new Error('Could not find rollup. Please install it in your project'); | ||
} | ||
for (const htmlScript of htmlAsset.outgoingRelations.filter( | ||
(relation) => | ||
relation.type === 'HtmlScript' && | ||
/^module$/i.test(relation.node.getAttribute('type')) | ||
)) { | ||
const entryPointAsset = htmlScript.to; | ||
|
||
const bundle = await rollup.rollup({ | ||
input: urlTools.fileUrlToFsPath(entryPointAsset.url), | ||
}); | ||
|
||
const { output } = await bundle.generate({}); | ||
for (const chunk of output) { | ||
const url = assetGraph.resolveUrl( | ||
entryPointAsset.nonInlineAncestor.url, | ||
chunk.fileName | ||
); | ||
|
||
const asset = assetGraph.addAsset({ | ||
type: 'JavaScript', | ||
text: chunk.code, | ||
url, | ||
}); | ||
|
||
if (chunk.fileName === entryPointAsset.fileName) { | ||
const relation = htmlAsset.addRelation( | ||
{ type: 'HtmlScript', to: asset }, | ||
'before', | ||
htmlScript | ||
); | ||
relation.node.setAttribute('type', 'module'); | ||
htmlAsset.markDirty(); | ||
} | ||
} | ||
htmlScript.detach(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "assetgraph-rollup", | ||
"version": "0.0.0", | ||
"description": "Add rollup bundling support to assetgraph", | ||
"main": "lib/assetgraph-rollup.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"devDependencies": { | ||
"assetgraph": "^6.2.1", | ||
"eslint": "^7.12.1", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-config-standard": "^16.0.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-mocha": "^8.0.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.2", | ||
"mocha": "^8.2.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.1.2", | ||
"rollup": "^2.32.1", | ||
"unexpected": "^11.15.0", | ||
"unexpected-assetgraph": "^1.1.2" | ||
}, | ||
"scripts": { | ||
"lint": "eslint . && prettier --check '**/*.{js,json,css,md}'", | ||
"test": "mocha", | ||
"test:ci": "npm run coverage", | ||
"coverage": "NODE_ENV=development nyc --reporter=lcov --reporter=text --all -- npm test && echo google-chrome coverage/lcov-report/index.html" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/assetgraph/assetgraph-rollup.git" | ||
}, | ||
"keywords": [ | ||
"assetgraph", | ||
"rollup", | ||
"bundle", | ||
"esm" | ||
], | ||
"author": "Andreas Lind <[email protected]>", | ||
"license": "BSD-3-Clause", | ||
"nyc": { | ||
"include": [ | ||
"lib/**" | ||
] | ||
}, | ||
"dependencies": { | ||
"urltools": "^0.4.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const pathModule = require('path'); | ||
const expect = require('unexpected') | ||
.clone() | ||
.use(require('unexpected-assetgraph')); | ||
const AssetGraph = require('assetgraph'); | ||
const assetgraphRollup = require('../lib/assetgraph-rollup'); | ||
|
||
describe('assetgraph-rollup', function () { | ||
it('should bundle a "trivial site"', async function () { | ||
const assetGraph = new AssetGraph({ | ||
root: pathModule.resolve( | ||
__dirname, | ||
'..', | ||
'testdata', | ||
'airquote-trivial-site', | ||
'gridfinder' | ||
), | ||
}); | ||
|
||
const [indexHtml] = await assetGraph.loadAssets('/src/index.html'); | ||
|
||
await assetGraph.populate({ followRelations: { crossorigin: false } }); | ||
|
||
await assetgraphRollup(assetGraph, indexHtml); | ||
// FIXME: This is just for testing: | ||
await assetGraph.writeAssetsToDisc( | ||
{ protocol: 'file:', isLoaded: true, isRedirect: false }, | ||
'foo' | ||
); | ||
}); | ||
}); |
Submodule gridfinder
added at
938b50