Skip to content
Snippets Groups Projects
Select Git revision
  • 99aff40744dca03062312cd0f8e17afbcf1a2d01
  • main default protected
  • renovate/lock-file-maintenance
  • demo protected
  • person-select-custom
  • dbp-translation-component
  • icon-set-mapping
  • port-i18next-parser
  • remove-sentry
  • favorites-and-recent-files
  • revert-6c632dc6
  • lit2
  • advertisement
  • wc-part
  • automagic
  • publish
  • wip-cleanup
  • demo-file-handling
18 results

rollup.utils.js

Blame
    • Reiter, Christoph's avatar
      68a87639
      Use the rollup resolve plugin for finding package asssets · 68a87639
      Reiter, Christoph authored
      Instead of hardcoding the paths of the node_modules directory we use the node-resolve
      plugin of rollup to find the root of the corresponding JS package and calcucate a path from
      there.
      
      Resolving a package requires calling an async function, so we have to use await in the rollup config.
      Luckily rollup supports configs wrapped in a promise, so we just have to wrap it in a function which returns
      a promise.
      68a87639
      History
      Use the rollup resolve plugin for finding package asssets
      Reiter, Christoph authored
      Instead of hardcoding the paths of the node_modules directory we use the node-resolve
      plugin of rollup to find the root of the corresponding JS package and calcucate a path from
      there.
      
      Resolving a package requires calling an async function, so we have to use await in the rollup config.
      Luckily rollup supports configs wrapped in a promise, so we just have to wrap it in a function which returns
      a promise.
    rollup.utils.js 1000 B
    import path from 'path';
    import url from 'url';
    import child_process from 'child_process';
    import resolve from '@rollup/plugin-node-resolve';
    
    export function getBuildInfo(build) {
        let remote = child_process.execSync('git config --get remote.origin.url').toString().trim();
        let commit = child_process.execSync('git rev-parse --short HEAD').toString().trim();
    
        let parsed = url.parse(remote);
        let newPath = parsed.path.slice(0, parsed.path.lastIndexOf('.'));
        let newUrl = parsed.protocol + '//' + parsed.host + newPath + '/commit/' + commit;
    
        return {
            info: commit,
            url: newUrl,
            time: new Date().toISOString(),
            env: build
        }
    }
    
    export async function getPackagePath(packageName, assetPath) {
        const r = resolve();
        const id = (await r.resolveId(packageName)).id;
        const packageInfo = r.getPackageInfoForId(id);
        const fullAssetPath = path.join(packageInfo.root, assetPath);
        return path.relative(process.cwd(), fullAssetPath);
    }