Skip to content

Commit

Permalink
Merge pull request #1 from togetter/patch/create-bundler-friendly-builds
Browse files Browse the repository at this point in the history
  • Loading branch information
tosuke authored Jun 18, 2021
2 parents 33169df + 1b0e6c9 commit cf997d4
Show file tree
Hide file tree
Showing 9 changed files with 1,987 additions and 1,776 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: publish-npm

on:
push:
tags:
- "v*"

defaults:
run:
working-directory: ./js

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Install Packages
run: yarn install --frozen-lockfile --non-interactive --no-progress
- name: Build
run: |
yarn run build:config
yarn run build
- name: Use GitHub npm registry
uses: actions/setup-node@v2
with:
registry-url: "https://npm.pkg.github.com"
- name: Publish
run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion js/.npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
registry = "https://registry.npmjs.org"

@togetter:registry = "https://npm.pkg.github.com"
File renamed without changes.
6 changes: 1 addition & 5 deletions js/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = api => {
return {
plugins: [
'@babel/plugin-transform-flow-strip-types',
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-spread',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-class-properties',
Expand All @@ -16,10 +15,7 @@ module.exports = api => {
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: 2,
modules: api.env('commonjs') || api.env('test') ? 'commonjs' : false,
forceAllTransforms: api.env('production')
modules: api.env('commonjs') || api.env('test') ? 'commonjs' : false
}
]
]
Expand Down
1 change: 1 addition & 0 deletions js/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from 'twitter-text'
54 changes: 28 additions & 26 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
{
"name": "twitter-text",
"name": "@togetter/twitter-text",
"description": "official twitter text linkification",
"version": "3.1.0",
"main": "dist/index.js",
"module": "dist/esm",
"version": "3.1.0-1",
"license": "Apache-2.0",
"main": "dist/twitter-text.cjs.js",
"module": "dist/twitter-text.esm.js",
"types": "index.d.ts",
"files": [
"dist"
"dist",
"index.d.ts"
],
"homepage": "https://github.com/twitter/twitter-text",
"homepage": "https://github.com/togetter/twitter-text",
"author": "Twitter Inc.",
"repository": {
"type": "git",
"url": "https://github.com/twitter/twitter-text.git"
"url": "https://github.com/togetter/twitter-text.git"
},
"sideEffects": false,
"devDependencies": {
"@babel/cli": "^7.4.0",
"@babel/core": "^7.4.0",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-export-default-from": "^7.7.4",
"@babel/plugin-proposal-export-namespace-from": "^7.7.4",
"@babel/plugin-syntax-dynamic-import": "^7.7.4",
"@babel/plugin-transform-flow-strip-types": "^7.3.4",
"@babel/plugin-transform-runtime": "^7.4.0",
"@babel/plugin-transform-spread": "^7.2.2",
"@babel/preset-env": "^7.4.0",
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.5",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-export-default-from": "^7.14.5",
"@babel/plugin-proposal-export-namespace-from": "^7.14.5",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-flow-strip-types": "^7.14.5",
"@babel/plugin-transform-spread": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
"@types/twitter-text": "^3.1.0",
"babel-eslint": "^10.0.1",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-add-module-exports": "^1.0.4",
"eslint": "^4.18.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
Expand All @@ -36,12 +43,8 @@
"prettier": "^1.10.2",
"qunitjs": "^1.23.1",
"rimraf": "^2.6.2",
"rollup": "^1.4.1",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-license": "^0.8.1",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup": "^2.51.2",
"rollup-plugin-license": "^2.5.0",
"uglify-js": "~2.4.3"
},
"scripts": {
Expand All @@ -52,12 +55,11 @@
"build:prod": "npm run lint:check && rimraf dist && NODE_ENV=production babel src --out-dir dist/esm && NODE_ENV=production BABEL_ENV=commonjs babel src --out-dir dist",
"lint:check": "eslint src rollup.config.js scripts",
"lint": "npm run lint:check -- --fix",
"prepublishOnly": "npm run build:prod",
"prepublishOnly": "npm run build",
"test": "npm run build:prepare && npm run build && rake test && rake test:conformance"
},
"dependencies": {
"@babel/runtime": "^7.3.1",
"core-js": "^2.5.0",
"punycode": "1.4.1",
"twemoji-parser": "^11.0.2"
}
Expand Down
36 changes: 20 additions & 16 deletions js/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/**
* Rollup is only used for development. See the build:prod script in package.json
* for the production build command.
*/
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import { defineConfig } from 'rollup';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import license from 'rollup-plugin-license';
import resolve from 'rollup-plugin-node-resolve';

const banner = `/*!
* <%= pkg.name %> <%= pkg.version %>
Expand All @@ -19,22 +15,30 @@ const banner = `/*!
* http://www.apache.org/licenses/LICENSE-2.0
*/`;

export default {
export default defineConfig({
input: 'src/index.js',
output: {
file: 'dist/twitter-text.js',
format: 'umd',
name: 'twttr.txt'
},
output: [
{
file: 'dist/twitter-text.cjs.js',
format: 'cjs',
sourcemap: true,
exports: 'named'
},
{
file: 'dist/twitter-text.esm.js',
format: 'esm',
sourcemap: true
}
],
external: ['twemoji-parser', 'punycode'],
plugins: [
babel({
exclude: ['node_modules/**'],
runtimeHelpers: true
babelHelpers: 'bundled'
}),
resolve({ preferBuiltins: false }),
commonjs(),
license({
banner: banner
})
]
};
});
50 changes: 50 additions & 0 deletions js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,56 @@ import splitTags from './splitTags';
import standardizeIndices from './standardizeIndices';
import tagAttrs from './tagAttrs';

export {
autoLink,
autoLinkCashtags,
autoLinkEntities,
autoLinkHashtags,
autoLinkUrlsCustom,
autoLinkUsernamesOrLists,
autoLinkWithJSON,
configs,
convertUnicodeIndices,
extractCashtags,
extractCashtagsWithIndices,
extractEntitiesWithIndices,
extractHashtags,
extractHashtagsWithIndices,
extractHtmlAttrsFromOptions,
extractMentions,
extractMentionsOrListsWithIndices,
extractMentionsWithIndices,
extractReplies,
extractUrls,
extractUrlsWithIndices,
getTweetLength,
getUnicodeTextLength,
hasInvalidCharacters,
hitHighlight,
htmlEscape,
isInvalidTweet,
isValidHashtag,
isValidList,
isValidTweetText,
isValidUrl,
isValidUsername,
linkTextWithEntity,
linkToCashtag,
linkToHashtag,
linkToMentionAndList,
linkToText,
linkToTextWithSymbol,
linkToUrl,
modifyIndicesFromUTF16ToUnicode,
modifyIndicesFromUnicodeToUTF16,
regexen,
removeOverlappingEntities,
parseTweet,
splitTags,
standardizeIndices,
tagAttrs
};

export default {
autoLink,
autoLinkCashtags,
Expand Down
Loading

0 comments on commit cf997d4

Please sign in to comment.