You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/07/22 09:38:31 UTC

[cordova-js] branch master updated: Make built JS output a bit prettier (#208)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-js.git


The following commit(s) were added to refs/heads/master by this push:
     new a6413dd  Make built JS output a bit prettier (#208)
a6413dd is described below

commit a6413ddcae1713f498b7bc2d942cb5db07f0cb57
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Mon Jul 22 11:38:27 2019 +0200

    Make built JS output a bit prettier (#208)
    
    In #205 I took great care to preserve the _exact_ format of the built
    JS code, so the build refactoring could be verified by diffing the
    build output. However, some of the existing formatting is sub-optimal
    so this commit optimizes it a little.
    
    Most notably, this commit will change file path comments to be relative
    paths, not absolute ones. An example for this:
    
    ```diff
    -// file: /home/raphinesse/code/cordova-android/cordova-js-src/exec.js
    +// file: ../cordova-android/cordova-js-src/exec.js
    ```
---
 build-tools/bundle.js  | 6 +++---
 build-tools/common.js  | 6 ++++--
 build-tools/modules.js | 8 +-------
 build-tools/scripts.js | 5 -----
 test/build.js          | 5 -----
 5 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/build-tools/bundle.js b/build-tools/bundle.js
index 2090587..3a7b97a 100644
--- a/build-tools/bundle.js
+++ b/build-tools/bundle.js
@@ -43,9 +43,9 @@ const bundleTemplate = ({
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
-\x20
+
      http://www.apache.org/licenses/LICENSE-2.0
-\x20
+
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -60,4 +60,4 @@ ${modules}
 window.cordova = require('cordova');
 ${includeScript('bootstrap')}
 })();
-`.trim();
+`.trimLeft();
diff --git a/build-tools/common.js b/build-tools/common.js
index 784881c..18af399 100644
--- a/build-tools/common.js
+++ b/build-tools/common.js
@@ -45,7 +45,9 @@ module.exports = {
 
     // TODO format path relative to pkg.json
     prependFileComment (f) {
-        const comment = `// file: ${f.path}`;
+        const relativePath = path.relative(pkgRoot, f.path);
+        const normalizedPath = path.posix.normalize(relativePath);
+        const comment = `// file: ${normalizedPath}`;
         const contents = [comment, f.contents].join('\n');
         return Object.assign({}, f, { contents });
     },
@@ -53,7 +55,7 @@ module.exports = {
     collectModules (dir) {
         return globby.sync(['**/*.js'], { cwd: dir })
             .map(fileName => ({
-                path: path.relative(pkgRoot, path.join(dir, fileName)),
+                path: path.join(dir, fileName),
                 moduleId: fileName.slice(0, -3)
             }))
             .map(file => ({ [file.moduleId]: file }))
diff --git a/build-tools/modules.js b/build-tools/modules.js
index 4ae28b8..b896055 100644
--- a/build-tools/modules.js
+++ b/build-tools/modules.js
@@ -29,12 +29,6 @@ const {
 } = require('./common');
 
 module.exports = function modules (config) {
-    for (const m of values(config.extraModules)) {
-        if (m.path.startsWith('../')) {
-            m.path = path.resolve(m.path);
-        }
-    }
-
     const commonModules = collectCommonModules();
     const modules = values(Object.assign(commonModules, config.extraModules));
     modules.sort((a, b) => a.moduleId.localeCompare(b.moduleId));
@@ -45,7 +39,7 @@ function collectCommonModules () {
     const modules = collectModules(path.join(pkgRoot, 'src/common'));
     modules[''] = {
         moduleId: '',
-        path: path.relative(pkgRoot, path.join(pkgRoot, 'src/cordova.js'))
+        path: path.join(pkgRoot, 'src/cordova.js')
     };
     return modules;
 }
diff --git a/build-tools/scripts.js b/build-tools/scripts.js
index 4fec388..ff0573a 100644
--- a/build-tools/scripts.js
+++ b/build-tools/scripts.js
@@ -47,14 +47,9 @@ function scriptPipeline (config) {
         .then(readContents)
         .then(config.preprocess)
         .then(stripLicenseHeader)
-        .then(prependEmptyLine)
         .then(prependFileComment);
 }
 
-function prependEmptyLine (f) {
-    return Object.assign({}, f, { contents: '\n' + f.contents });
-}
-
 function indexByModuleId (files) {
     return files
         .reduce((acc, f) => Object.assign(acc, { [f.moduleId]: f }), {});
diff --git a/test/build.js b/test/build.js
index 5c2a007..b94ada6 100755
--- a/test/build.js
+++ b/test/build.js
@@ -35,11 +35,6 @@ function collectTestBuildModules () {
         const moduleId = path.posix.join(platform, 'exec');
         modules[moduleId] = Object.assign({}, modules.exec, { moduleId });
 
-        // Remove plugin/* modules to minimize diff to old build
-        Object.keys(modules)
-            .filter(k => k.startsWith('plugin/'))
-            .forEach(k => delete modules[k]);
-
         return modules;
     });
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org