-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create a separate chunk for watch mode via a dynamic import * Bundle chokidar * Handle conditional fsevents import * Only run tests on Node 10 and 12 as we want to do this anyway and chokidar depends on utils.promisify * Improve chunking * Refactor and simplify watcher * Make watcher a proper parameter * Only unwatch and watch on Linux systems * No longer run JS files through TypeScript for improved bundling performance
- Loading branch information
1 parent
ee46189
commit 196f3ef
Showing
27 changed files
with
1,921 additions
and
3,218 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
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
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,14 @@ | ||
import MagicString from 'magic-string'; | ||
|
||
export default function addBinShebang() { | ||
return { | ||
name: 'add-bin-shebang', | ||
renderChunk(code, chunkInfo) { | ||
if (chunkInfo.fileName === 'bin/rollup') { | ||
const magicString = new MagicString(code); | ||
magicString.prepend('#!/usr/bin/env node\n\n'); | ||
return { code: magicString.toString(), map: magicString.generateMap({ hires: 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,25 @@ | ||
import MagicString from 'magic-string'; | ||
|
||
const FSEVENTS_REQUIRE = "require('fsevents')"; | ||
const REPLACEMENT = "require('../../../src/watch/fsevents-importer').getFsEvents()"; | ||
|
||
export default function conditionalFsEventsImport() { | ||
return { | ||
name: 'conditional-fs-events-import', | ||
transform(code, id) { | ||
if (id.endsWith('fsevents-handler.js')) { | ||
const requireStatementPos = code.indexOf(FSEVENTS_REQUIRE); | ||
if (requireStatementPos < 0) { | ||
throw new Error(`Could not find expected fsevents import "${FSEVENTS_REQUIRE}"`); | ||
} | ||
const magicString = new MagicString(code); | ||
magicString.overwrite( | ||
requireStatementPos, | ||
requireStatementPos + FSEVENTS_REQUIRE.length, | ||
REPLACEMENT | ||
); | ||
return { code: magicString.toString(), map: magicString.generateMap({ hires: 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,23 @@ | ||
const expectedAcornImport = "import acorn, { Parser } from 'acorn';"; | ||
const newAcornImport = "import * as acorn from 'acorn';\nimport { Parser } from 'acorn';"; | ||
|
||
// by default, rollup-plugin-commonjs will translate require statements as default imports | ||
// which can cause issues for secondary tools that use the ESM version of acorn | ||
export default function fixAcornEsmImport() { | ||
let found = false; | ||
|
||
return { | ||
name: 'fix-acorn-esm-import', | ||
renderChunk(code) { | ||
return code.replace(expectedAcornImport, () => { | ||
found = true; | ||
return newAcornImport; | ||
}); | ||
}, | ||
writeBundle() { | ||
if (!found) { | ||
this.error('Could not find expected acorn import, please examine generated code.'); | ||
} | ||
} | ||
}; | ||
} |
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,57 @@ | ||
import fs from 'fs'; | ||
|
||
export default function generateLicenseFile(dependencies) { | ||
const coreLicense = fs.readFileSync('LICENSE-CORE.md'); | ||
const licenses = new Set(); | ||
const dependencyLicenseTexts = dependencies | ||
.sort(({ name: nameA }, { name: nameB }) => (nameA > nameB ? 1 : -1)) | ||
.map(({ name, license, licenseText, author, maintainers, contributors, repository }) => { | ||
let text = `## ${name}\n`; | ||
if (license) { | ||
text += `License: ${license}\n`; | ||
} | ||
const names = new Set(); | ||
if (author && author.name) { | ||
names.add(author.name); | ||
} | ||
for (const person of maintainers.concat(contributors)) { | ||
if (person && person.name) { | ||
names.add(person.name); | ||
} | ||
} | ||
if (names.size > 0) { | ||
text += `By: ${Array.from(names).join(', ')}\n`; | ||
} | ||
if (repository) { | ||
text += `Repository: ${repository.url || repository}\n`; | ||
} | ||
if (licenseText) { | ||
text += | ||
'\n' + | ||
licenseText | ||
.trim() | ||
.replace(/(\r\n|\r)/gm, '\n') | ||
.split('\n') | ||
.map(line => `> ${line}`) | ||
.join('\n') + | ||
'\n'; | ||
} | ||
licenses.add(license); | ||
return text; | ||
}) | ||
.join('\n---------------------------------------\n\n'); | ||
const licenseText = | ||
`# Rollup core license\n` + | ||
`Rollup is released under the MIT license:\n\n` + | ||
coreLicense + | ||
`\n# Licenses of bundled dependencies\n` + | ||
`The published Rollup artifact additionally contains code with the following licenses:\n` + | ||
`${Array.from(licenses).join(', ')}\n\n` + | ||
`# Bundled dependencies:\n` + | ||
dependencyLicenseTexts; | ||
const existingLicenseText = fs.readFileSync('LICENSE.md', 'utf8'); | ||
if (existingLicenseText !== licenseText) { | ||
fs.writeFileSync('LICENSE.md', licenseText); | ||
console.warn('LICENSE.md updated. You should commit the updated file.'); | ||
} | ||
} |
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
Oops, something went wrong.