Git Product home page Git Product logo

rollup-plugin-version-injector's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar djhouseknecht avatar rednil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rollup-plugin-version-injector's Issues

Any way to use multi-line comment style instead of single-line with `injectInComments`?

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.

Log level 'log' items are still logged with 'warn' or 'error' logLevel

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!

Broken sourcemap

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?

Unable to get version injector to work

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.

Default file regexp leads to skipped entries

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:

  1. Create a js file with let version = [VI]{date}[/VI].
  2. Create a rollup.config.js with the following default export:
    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'
                }
            })
        ]
    }];
  1. Execute 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.

Updating with hot reload

Is it possible to achieve having the version (taken from package.json) updated when using hot reload?

Contributing features

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:

  1. Git integration (show the current branch/workspace status)
  2. Comment in the console as an opt-in option for this project
  3. An optional window global for quickly (but quietly) referencing the recent build without looking at the source.

If you're open to these features I'd be happy to do the work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.