Jelajahi Sumber

New sync version (#1600)

New sync version
Renée Kooi 5 tahun lalu
induk
melakukan
b64705fce2

+ 4 - 3
babel.config.js

@@ -13,9 +13,10 @@ module.exports = (api) => {
       }]
     ],
     plugins: [
-      '@babel/plugin-proposal-object-rest-spread',
+      ['@babel/plugin-proposal-class-properties', { loose: true }],
       '@babel/plugin-transform-object-assign',
-      ['@babel/plugin-transform-react-jsx', { pragma: 'h' }]
-    ]
+      ['@babel/plugin-transform-react-jsx', { pragma: 'h' }],
+      process.env.IS_RELEASE_BUILD && 'babel-plugin-inline-package-json'
+    ].filter(Boolean)
   }
 }

+ 112 - 0
bin/after-version-bump.js

@@ -0,0 +1,112 @@
+#!/usr/bin/env node
+// Called by the `version` npm script.
+// This is run _after_ lerna updates the version numbers,
+// but _before_ it commits, so we have time to update the
+// version numbers throughout the repo and add it to the
+// release commit.
+// After updating version numbers, this runs a full
+// IS_RELEASE_BUILD=1 build, so that the version numbers
+// are properly embedded in the JS bundles.
+// NOTE this _amends_ the previous commit, which should
+// already be a "Release" commit generated by bin/release.
+
+const lastCommitMessage = require('last-commit-message')
+const { spawn } = require('child_process')
+const { promisify } = require('util')
+const once = require('events.once')
+const globby = require('globby')
+const fs = require('fs')
+const readFile = promisify(fs.readFile)
+const writeFile = promisify(fs.writeFile)
+
+async function replaceInFile (filename, replacements) {
+  let content = await readFile(filename, 'utf8')
+  for (const [rx, replacement] of replacements) {
+    content = content.replace(rx, replacement)
+  }
+
+  await writeFile(filename, content, 'utf8')
+}
+
+async function updateVersions (files, packageName) {
+  const { version } = require(`../packages/${packageName}/package.json`)
+
+  // uppy → uppy
+  // @uppy/robodog → uppy/robodog
+  const urlPart = packageName === 'uppy' ? packageName : packageName.slice(1)
+
+  const replacements = new Map([
+    [RegExp(`${urlPart}/v\\d+\\.\\d+\\.\\d+\\/`, 'g'), `${urlPart}/v${version}/`]
+    // maybe more later
+  ])
+
+  console.log('replacing', replacements, 'in', files.length, 'files')
+
+  for (const f of files) {
+    await replaceInFile(f, replacements)
+  }
+}
+
+async function gitAdd (files) {
+  const git = spawn('git', ['add', ...files], { stdio: 'inherit' })
+  const [exitCode] = await once(git, 'exit')
+  if (exitCode !== 0) {
+    throw new Error(`git add failed with ${exitCode}`)
+  }
+}
+
+// Run the build as a release build (that inlines version numbers etc.)
+async function npmRunBuild () {
+  const npmRun = spawn('npm', ['run', 'build'], {
+    stdio: 'inherit',
+    env: {
+      ...process.env,
+      FRESH: true, // force rebuild everything
+      IS_RELEASE_BUILD: true
+    }
+  })
+  const [exitCode] = await once(npmRun, 'exit')
+  if (exitCode !== 0) {
+    throw new Error(`npm run build failed with ${exitCode}`)
+  }
+}
+
+async function main () {
+  if (process.env.ENDTOEND === '1') {
+    console.log('Publishing for e2e tests, skipping version number sync.')
+    process.exit(0)
+  }
+
+  const message = await lastCommitMessage()
+  if (message.trim() !== 'Release') {
+    console.error(`Last commit is not a release commit, but '${message}'`)
+    process.exit(1)
+  }
+
+  const files = await globby([
+    'README.md',
+    'examples/**/*.html',
+    'packages/*/README.md',
+    'packages/@uppy/*/README.md',
+    'website/src/docs/**',
+    'website/src/examples/**',
+    'website/themes/uppy/layout/**',
+    '!**/node_modules/**'
+  ])
+
+  await updateVersions(files, 'uppy')
+  await updateVersions(files, '@uppy/robodog')
+  await updateVersions(files, '@uppy/locales')
+
+  // gitignored files were updated for the npm package, but can't be updated
+  // on git.
+  const isIgnored = await globby.gitignore()
+  await gitAdd(files.filter((filename) => !isIgnored(filename)))
+
+  await npmRunBuild()
+}
+
+main().catch(function (err) {
+  console.error(err.stack)
+  process.exit(1)
+})

+ 9 - 6
bin/disc.js

@@ -8,12 +8,15 @@ const disc = require('disc')
 
 const outputPath = path.join(__dirname, '../website/src/disc.html')
 
-function minifyify () {
-  return minify({
-    sourceMap: false,
-    toplevel: true,
-    compress: { unsafe: true }
-  })
+function minifyify (filename) {
+  if (filename.endsWith('.js')) {
+    return minify({
+      sourceMap: false,
+      toplevel: true,
+      compress: { unsafe: true }
+    })
+  }
+  return new PassThrough()
 }
 
 const bundler = browserify(path.join(__dirname, '../packages/uppy/index.js'), {

+ 8 - 3
bin/release

@@ -10,6 +10,9 @@ __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
 __base="$(basename ${__file} .sh)"
 __root="$(cd "$(dirname "${__dir}")" && pwd)"
 
+is_local="${LOCAL:-0}"
+echo "Local release: $is_local"
+
 if [[ ! "$@" =~ -y ]]; then
   echo "Make sure to read https://uppy.io/docs/contributing#Releases!"
   echo "Press Enter when ready, or Ctrl+C if you still need to do something."
@@ -17,7 +20,7 @@ if [[ ! "$@" =~ -y ]]; then
   read
 fi
 
-if [[ ! "$(npm get registry)" =~ https://registry\.npmjs\.(com|org)/? ]]; then
+if [ $is_local == "0" ] && [[ ! "$(npm get registry)" =~ https://registry\.npmjs\.(com|org)/? ]]; then
   echo "Found unexpected npm registry: $(npm get registry)"
   echo "Run this to fix:"
   echo ""
@@ -71,5 +74,7 @@ lerna version --amend --no-push --exact
 
 lerna publish from-git
 
-git push
-git push --tags
+if [ $is_local == "0" ]; then
+  git push
+  git push --tags
+fi

+ 0 - 43
bin/sync-version-numbers

@@ -1,43 +0,0 @@
-#!/usr/bin/env bash
-
-# Called by the `version` npm script.
-# This is run _after_ lerna updates the version numbers,
-# but _before_ it commits, so we have time to update the
-# version numbers throughout the repo and add it to the
-# release commit.
-# NOTE this _amends_ the previous commit, which should
-# already be a "Release" commit generated by bin/release.
-
-set -o pipefail
-set -o errexit
-set -o nounset
-
-# Set magic variables for current file & dir
-# __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-# __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
-# __base="$(basename ${__file} .sh)"
-# __root="$(cd "$(dirname "${__dir}")" && pwd)"
-
-# disable this script
-# until upload-to-cdn is refactored to publish multiple packages
-# remove when upload-to-cdn is back
-exit 0
-
-if [ "${ENDTOEND:=0}" = "1" ]; then
-  echo "Publishing for e2e tests, skipping version number sync."
-  exit 0
-fi
-
-commit_message="$(git log -1 --pretty=%B)"
-if [ "${commit_message}" != "Release" ]; then
-  echo "Last commit is not a release commit, but '${commit_message}'"
-  exit 1
-fi
-
-version_files="./examples/ README.md bin/upload-to-cdn.sh website/src/examples/ website/src/docs/ website/themes/uppy/layout/"
-main_package_version=$(node -p "require('./packages/uppy/package.json').version")
-# Legacy defeater for also renaming the old /dist/ locations, can be removed as soon as everything's on the new dist-less thing
-replace-x -r 'uppy/v\d+\.\d+\.\d+/dist/' "uppy/v$main_package_version/" ${version_files} --exclude=node_modules
-replace-x -r 'uppy/v\d+\.\d+\.\d+/' "uppy/v$main_package_version/" ${version_files} --exclude=node_modules
-# replace-x -r 'uppy@\d+\.\d+\.\d+' "uppy@$main_package_version" ${version_files} --exclude=node_modules
-git add ${version_files} # add changes to the Release commit

File diff ditekan karena terlalu besar
+ 356 - 555
package-lock.json


+ 7 - 4
package.json

@@ -11,7 +11,7 @@
   "devDependencies": {
     "@babel/cli": "^7.4.4",
     "@babel/core": "^7.4.5",
-    "@babel/plugin-proposal-object-rest-spread": "^7.4.4",
+    "@babel/plugin-proposal-class-properties": "^7.4.4",
     "@babel/plugin-transform-object-assign": "^7.2.0",
     "@babel/plugin-transform-proto-to-assign": "^7.4.4",
     "@babel/plugin-transform-react-jsx": "^7.3.0",
@@ -23,6 +23,7 @@
     "aliasify": "^2.1.0",
     "autoprefixer": "^9.5.1",
     "babel-jest": "^24.8.0",
+    "babel-plugin-inline-package-json": "^2.0.0",
     "babelify": "^10.0.0",
     "browser-resolve": "^1.11.3",
     "browser-sync": "^2.26.5",
@@ -43,15 +44,18 @@
     "eslint-plugin-promise": "^4.1.1",
     "eslint-plugin-react": "^7.12.4",
     "eslint-plugin-standard": "^4.0.0",
+    "events.once": "^2.0.2",
     "exorcist": "^1.0.1",
     "fakefile": "0.0.9",
     "flat": "^4.1.0",
     "github-contributors-list": "1.2.3",
     "glob": "^7.1.3",
+    "globby": "^9.2.0",
     "gzip-size": "^5.0.0",
     "isomorphic-fetch": "2.2.1",
     "jest": "^24.7.1",
     "json3": "^3.3.2",
+    "last-commit-message": "^1.0.0",
     "lerna": "^3.14.1",
     "lint-staged": "^8.1.7",
     "minify-stream": "^1.2.0",
@@ -119,7 +123,7 @@
     "test:watch": "jest --watch",
     "test": "npm-run-all lint test:locale-packs test:unit test:type test:companion",
     "uploadcdn": "bin/upload-to-cdn.sh",
-    "version": "./bin/sync-version-numbers",
+    "version": "node ./bin/after-version-bump.js",
     "watch:css": "onchange 'packages/**/*.scss' --initial --verbose -- npm run build:css",
     "watch:js:bundle": "onchange 'packages/{@uppy/,}*/src/**/*.js' --initial --verbose -- npm run build:bundle",
     "watch:js:lib": "onchange 'packages/{@uppy/,}*/src/**/*.js' --initial --verbose -- npm run build:lib",
@@ -147,6 +151,5 @@
     "testMatch": [
       "**/packages/**/*.test.js"
     ]
-  },
-  "dependencies": {}
+  }
 }

+ 2 - 0
packages/@uppy/aws-s3-multipart/src/index.js

@@ -34,6 +34,8 @@ function assertServerError (res) {
 }
 
 module.exports = class AwsS3Multipart extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'uploader'

+ 2 - 0
packages/@uppy/aws-s3/src/index.js

@@ -28,6 +28,8 @@ function assertServerError (res) {
 }
 
 module.exports = class AwsS3 extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'uploader'

+ 2 - 0
packages/@uppy/companion-client/src/RequestClient.js

@@ -8,6 +8,8 @@ function stripSlash (url) {
 }
 
 module.exports = class RequestClient {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     this.uppy = uppy
     this.opts = opts

+ 2 - 0
packages/@uppy/core/src/index.js

@@ -18,6 +18,8 @@ const Plugin = require('./Plugin') // Exported from here.
  * adds/removes files and metadata.
  */
 class Uppy {
+  static VERSION = require('../package.json').version
+
   /**
   * Instantiate Uppy
   * @param {object} opts — Uppy options

+ 2 - 0
packages/@uppy/dashboard/src/index.js

@@ -44,6 +44,8 @@ function createPromise () {
  * Dashboard UI with previews, metadata editing, tabs for various services and more
  */
 module.exports = class Dashboard extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.id = this.opts.id || 'Dashboard'

+ 2 - 0
packages/@uppy/drag-drop/src/index.js

@@ -10,6 +10,8 @@ const { h } = require('preact')
  *
  */
 module.exports = class DragDrop extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'acquirer'

+ 2 - 0
packages/@uppy/dropbox/src/index.js

@@ -4,6 +4,8 @@ const ProviderViews = require('@uppy/provider-views')
 const { h } = require('preact')
 
 module.exports = class Dropbox extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.id = this.opts.id || 'Dropbox'

+ 2 - 0
packages/@uppy/file-input/src/index.js

@@ -4,6 +4,8 @@ const Translator = require('@uppy/utils/lib/Translator')
 const { h } = require('preact')
 
 module.exports = class FileInput extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.id = this.opts.id || 'FileInput'

+ 2 - 0
packages/@uppy/form/src/index.js

@@ -9,6 +9,8 @@ const getFormData = require('get-form-data').default || require('get-form-data')
  * Form
  */
 module.exports = class Form extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'acquirer'

+ 2 - 0
packages/@uppy/golden-retriever/src/index.js

@@ -11,6 +11,8 @@ const MetaDataStore = require('./MetaDataStore')
 * https://uppy.io/blog/2017/07/golden-retriever/
 */
 module.exports = class GoldenRetriever extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'debugger'

+ 2 - 0
packages/@uppy/google-drive/src/index.js

@@ -4,6 +4,8 @@ const DriveProviderViews = require('./DriveProviderViews')
 const { h } = require('preact')
 
 module.exports = class GoogleDrive extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.id = this.opts.id || 'GoogleDrive'

+ 2 - 0
packages/@uppy/informer/src/index.js

@@ -9,6 +9,8 @@ const { h } = require('preact')
  *
  */
 module.exports = class Informer extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'progressindicator'

+ 2 - 0
packages/@uppy/instagram/src/index.js

@@ -4,6 +4,8 @@ const ProviderViews = require('@uppy/provider-views')
 const { h } = require('preact')
 
 module.exports = class Instagram extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.id = this.opts.id || 'Instagram'

+ 2 - 0
packages/@uppy/progress-bar/src/index.js

@@ -6,6 +6,8 @@ const { h } = require('preact')
  *
  */
 module.exports = class ProgressBar extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.id = this.opts.id || 'ProgressBar'

+ 2 - 0
packages/@uppy/provider-views/src/index.js

@@ -38,6 +38,8 @@ class CloseWrapper extends Component {
  * Class to easily generate generic views for Provider plugins
  */
 module.exports = class ProviderView {
+  static VERSION = require('../package.json').version
+
   /**
    * @param {object} instance of the plugin
    */

+ 2 - 0
packages/@uppy/redux-dev-tools/src/index.js

@@ -7,6 +7,8 @@ const { Plugin } = require('@uppy/core')
  * and https://github.com/zalmoxisus/mobx-remotedev/blob/master/src/monitorActions.js
  */
 module.exports = class ReduxDevTools extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'debugger'

+ 2 - 1
packages/@uppy/robodog/src/index.js

@@ -7,5 +7,6 @@ module.exports = {
   dashboard,
   form,
   pick,
-  upload
+  upload,
+  VERSION: require('../package.json').version
 }

+ 2 - 0
packages/@uppy/status-bar/src/index.js

@@ -10,6 +10,8 @@ const getBytesRemaining = require('@uppy/utils/lib/getBytesRemaining')
  * progress percentage and time remaining.
  */
 module.exports = class StatusBar extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.id = this.opts.id || 'StatusBar'

+ 2 - 0
packages/@uppy/store-default/src/index.js

@@ -2,6 +2,8 @@
  * Default store that keeps state in a simple object.
  */
 class DefaultStore {
+  static VERSION = require('../package.json').version
+
   constructor () {
     this.state = {}
     this.callbacks = []

+ 2 - 0
packages/@uppy/store-redux/src/index.js

@@ -16,6 +16,8 @@ const defaultSelector = (id) => (state) => state.uppy[id]
  *    Defaults to retrieving `state.uppy[opts.id]`. Override if you placed Uppy state elsewhere in the Redux store.
  */
 class ReduxStore {
+  static VERSION = require('../package.json').version
+
   constructor (opts) {
     this._store = opts.store
     this._id = opts.id || cuid()

+ 2 - 0
packages/@uppy/thumbnail-generator/src/index.js

@@ -8,6 +8,8 @@ const isPreviewSupported = require('@uppy/utils/lib/isPreviewSupported')
  */
 
 module.exports = class ThumbnailGenerator extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'thumbnail'

+ 2 - 0
packages/@uppy/transloadit/src/index.js

@@ -25,6 +25,8 @@ const TL_UPPY_SERVER = /https?:\/\/api2(?:-\w+)?\.transloadit\.com\/uppy-server/
  * Upload files to Transloadit using Tus.
  */
 module.exports = class Transloadit extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'uploader'

+ 2 - 0
packages/@uppy/tus/src/index.js

@@ -48,6 +48,8 @@ function createEventTracker (emitter) {
  *
  */
 module.exports = class Tus extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'uploader'

+ 2 - 0
packages/@uppy/url/src/index.js

@@ -10,6 +10,8 @@ const forEachDroppedOrPastedUrl = require('./utils/forEachDroppedOrPastedUrl')
  *
  */
 module.exports = class Url extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.id = this.opts.id || 'Url'

+ 2 - 0
packages/@uppy/webcam/src/index.js

@@ -35,6 +35,8 @@ function getMediaDevices () {
  * Webcam
  */
 module.exports = class Webcam extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.mediaDevices = getMediaDevices()

+ 2 - 0
packages/@uppy/xhr-upload/src/index.js

@@ -22,6 +22,8 @@ function buildResponseError (xhr, error) {
 }
 
 module.exports = class XHRUpload extends Plugin {
+  static VERSION = require('../package.json').version
+
   constructor (uppy, opts) {
     super(uppy, opts)
     this.type = 'uploader'

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini