djhouseknecht / rollup-plugin-version-injector Goto Github PK
View Code? Open in Web Editor NEWrollup.js plugin to auto inject the current version into the source code
rollup.js plugin to auto inject the current version into the source code
I'm migrating from Webpack to Rollup, and am looking to this plugin as a replacement for webpack-auto-inject-version. It seems, though, that this plugin can only inject comments as single-line (//
) style comments. Is there a way to set up injectInComments
to use multiline (/* */
) style comments instead?
The reason I ask is because, in the past, an aggressive bundling config in a project using my library put everything on a single line, including the single-line version comment. As a result about half the bundled code failed to work... The fix was to set multiLineCommentType: true
on the Webpack version injector to inject the version comment as a multiline comment block instead.
Travis-ci is going away. Need to move building and releasing to github actions. Here is some info on how/what to do:
https://travis-ci.community/t/travis-build-stuck-on-trying-to-build/10796
Hi, thanks for a great plugin!
The only thing I've got a problem with is that even with the logLevel set to 'warn' or 'error', I'm still getting the following logged to my console:
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [error] code not set in VIInjector called from injectIntoTags()
[VI] [error] code not set in VIInjector called from injectIntoComments()
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] found and replaced [1] version tags in poductivity-client.entry.esm.js
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
[VI] [log ] version-injector started with version "0.9.0"
[VI] [log ] version-injector finished
My config is as follows:
versionInjector({
injectInComments: {
fileRegexp: /\.(js|css)$/,
tag: 'Poductivity SDK version: {version} - Built {date}',
dateFormat: 'mmmm d, yyyy HH:MM:ss',
},
logLevel: 'warn',
}),
The logLevel is definitely being read from the config, because if I change it to 'debug' I get way more logged.
I'm using version 1.3.0, and the context is a stenciljs app.
Thanks!
My application creates multiple chunks but this plugin cannot work with multiple chunk output since it requires output.file :(
Hello,
I started to use this plugin just now and, with the default configuration, it works as expected.
But it also produces a warning:
(!) Broken sourcemap
https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect
Plugins that transform code (such as 'version-injector') should generate accompanying sourcemaps
Is this a known issue? Am I missing something in the configuration?
I have a typescript file that is bundled into .min.js. I am able to get the version injector plugin to work with my setup.
Shouldn't .min.js match the default file regex ?
Debug log:
[VI] [debug] retrieved package.json path "./package.json" and version "0.1.0-alpha"
[VI] [log ] version-injector started with version "0.1.0-alpha"
[VI] [debug] config {
injectInComments: {
fileRegexp: /\.(js|html|css)$/,
tag: 'Version: {version} - {date}',
dateFormat: 'mmmm d, yyyy HH:MM:ss'
},
injectInTags: {
fileRegexp: /\.(js|html|css)$/,
tagId: 'VI',
dateFormat: 'mmmm d, yyyy HH:MM:ss'
},
packageJson: './package.json',
logLevel: 'debug',
logger: {
log: [Function: bound consoleCall],
warn: [Function: bound consoleCall],
dir: [Function: bound consoleCall],
time: [Function: bound consoleCall],
timeEnd: [Function: bound consoleCall],
timeLog: [Function: bound consoleCall],
trace: [Function: bound consoleCall],
assert: [Function: bound consoleCall],
clear: [Function: bound consoleCall],
count: [Function: bound consoleCall],
countReset: [Function: bound consoleCall],
group: [Function: bound consoleCall],
groupEnd: [Function: bound consoleCall],
table: [Function: bound consoleCall],
debug: [Function: bound consoleCall],
info: [Function: bound consoleCall],
dirxml: [Function: bound consoleCall],
error: [Function: bound consoleCall],
groupCollapsed: [Function: bound consoleCall],
Console: [Function: Console],
profile: [Function: profile],
profileEnd: [Function: profileEnd],
timeStamp: [Function: timeStamp],
context: [Function: context],
[Symbol(kBindStreamsEager)]: [Function: bound ],
[Symbol(kBindStreamsLazy)]: [Function: bound ],
[Symbol(kBindProperties)]: [Function: bound ],
[Symbol(kWriteToConsole)]: [Function: bound ],
[Symbol(kGetInspectOptions)]: [Function: bound ],
[Symbol(kFormatForStdout)]: [Function: bound ],
[Symbol(kFormatForStderr)]: [Function: bound ]
},
exclude: []
}
[VI] [debug] output file dist/foo.min.js
[VI] [debug] file name amd
[VI] [error] code not set in VIInjector called from injectIntoTags()
[VI] [debug] injectInTages skipped because it was set to "false" or fileName did not match expression {
fileRegexp: /\.(js|html|css)$/,
tagId: 'VI',
dateFormat: 'mmmm d, yyyy HH:MM:ss'
}
[VI] [error] code not set in VIInjector called from injectIntoComments()
[VI] [debug] injectIntoComments skipped because it was set to "false" or fileName did not match expression {
fileRegexp: /\.(js|html|css)$/,
tag: 'Version: {version} - {date}',
dateFormat: 'mmmm d, yyyy HH:MM:ss'
}
[VI] [log ] file was not changed. did not write to file "amd"
[VI] [log ] version-injector finished
created dist/foo.min.js in 8.1s
✨ Done in 8.90s.
Travis CI is not building the current code changes. This is preventing the release with the bug fixes. Issue opened with travis.
https://travis-ci.community/t/travis-build-stuck-on-trying-to-build/10796
When rollup is set up to build multiple inputs and more than one input uses the version injector plugin, VI will fail to replace entries in some of the outputs (when default regex is used).
This happens because the default regex has a global flag. With the global flag set, RegExp.prototype.test()
works iteratively and tries to search from its last index whenever it is called. From MDN:
When a regex has the global flag set, test() will advance the lastIndex of the regex. (RegExp.prototype.exec() also advances the lastIndex property.)
Further calls to test(str) will resume searching str starting from lastIndex. The lastIndex property will continue to increase each time test() returns true.
To avoid this issue, I would recommend defaulting to a non-global regex, since it is only being tested once per file. E.g.: /\.(js|html|css)$/
.
Steps to reproduce:
let version = [VI]{date}[/VI]
. import versionInjector from 'rollup-plugin-version-injector';
export default [{
input: 'input.js',
output: {
file: 'dist/out1.js',
format: 'iife',
name: 'Foo',
},
plugins: [
versionInjector({
injectInComments: false,
injectInTags: {
dateFormat: 'isoUtcDateTime'
}
})
]
}, {
input: 'input.js',
output: {
file: 'dist/out2.js',
format: 'iife',
name: 'Foo',
},
plugins: [
versionInjector({
injectInComments: false,
injectInTags: {
dateFormat: 'isoUtcDateTime'
}
})
]
}, {
input: 'input.js',
output: {
file: 'dist/out3.js',
format: 'iife',
name: 'Foo',
},
plugins: [
versionInjector({
injectInComments: false,
injectInTags: {
dateFormat: 'isoUtcDateTime'
}
})
]
}];
rollup --config
. String replacement will fail in at least one of the files (for me it's usually the last one).Workaround:
Set fileRegexp: /\.(js|html|css)$/,
in the version injector plugin configuration.
Is it possible to achieve having the version (taken from package.json) updated when using hot reload?
Hey @djhouseknecht!
I noticed that this project is based on the now unmaintained webpack-auto-inject-version. I had used the same plugin as inspiration to write my own webpack 5 compliant version: https://github.com/trev-dev/webpack-plugin-log-version
I'm new to rollup, but I like it! I was wondering if you'd be interested in receiving some pull requests related to some of the features I wrote. Namely:
If you're open to these features I'd be happy to do the work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.